Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Mar 31 '11 at 21:34

This question came from our site for professional and enthusiast programmers.

up vote 10 down vote accepted


curl -u user:password 'ftp://mysite/%2fusers/myfolder/myfile/raw' -o ~/Downloads/myfile.raw

In 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 ~/.netrc is not particularly secure either, but it at least is hidden from ps -ef.

  • Your password is sent in clear text. If the server supports it, use curl --ssl-reqd or curl ftps://mysite/...

  • Using SFTP (the SSH file transfer protocol) would be even better.

share|improve this answer
Worked great. Not quite sure I fully comprehend how the %2f is used, as you're also using /, but hey it works, so I'm not gonna complain. Thanks for the help! – Josiah Apr 1 '11 at 19:44
@Josiah: It seems that the URL "path" is split by /, and each argument is sent with a CWD command: %2fusers/myfolder as CWD /users, CWD myfolder. See RFC 1738 on this topic. – grawity Apr 1 '11 at 19:51
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.

share|improve this answer


curl "ftp://user:password@myftpsite/users/myfolder/myfile.raw"

(If the remote file name is 'myfile.raw')

share|improve this answer
When I try that, I get the following error: "curl: (9) Server denied you to change to the given directory". I believe that it why I needed to use the -Q "CWD" command. – Josiah Mar 31 '11 at 21:22

As 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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .