I'm trying to use a cURL command to download a file from an FTP server to a local drive on my computer. I've tried
curl "ftp://myftpsite" --user name:password -Q "CWD /users/myfolder/" -O "myfile.raw"
But it returns an error that says:
curl: Remote file name has no length!
curl: try 'curl --help' or 'curl --manual' for more information
curl: (6) Could not resolve host: myfile.raw; No data record of requested type
I've tried some other methods, but nothing seems to work.
Also, I'm not quite sure how to specify which folder I want the file to be downloaded to. How would I do that?
4 Answers
Try
curl -u user:password 'ftp://mysite/%2fusers/myfolder/myfile/raw' -o ~/Downloads/myfile.rawIn FTP URLs, the path is relative to the starting directory (usually your homedir). You need to specify an absolute path, and that means using %2f to specify /. This is needed because the path in ftp: URLs is treated as a list of slash-separated names, each of which is supposed to be given to a separate CWD command. The %2f is decoded after splitting. See RFC 1738 and FTP URLs.
As for the output location, just give a path to -o.
Security suggestions:
Don't put your password in the URL. Storing it in
~/.netrcis not particularly secure either, but it at least is hidden fromps -ef.Your password is sent in clear text. If the server supports it, use
curl --ssl-reqdorcurl ftps://mysite/...Using SFTP (the SSH file transfer protocol) would be even better.
curl -T /users/myfolder/myfile.raw -u username:password "ftp://myftpsite/path/myfile.raw"I use this all the time. It works like a charm.
1Try:
curl "ftp://user:password@myftpsite/users/myfolder/myfile.raw"(If the remote file name is 'myfile.raw')
1As yan suggests,
curl "ftp://user:password@myftpsite/users/myfolder/myfile.raw"
should work, but some FTP servers use security policies that are not standards-compliant. In those cases, the --ftp-method singlecwd or --ftp-method nocwd option may help.