So I've got an interesting issue at the moment. I'm attempting to use curl (7.15.5 on CentOS) to retrieve a file from a remote FTP server. Our client changed something last weekend, because it worked on Friday and doesn't now.

I can FTP in using the CLI client, and get a directory listing just fine, although I have to issue "passive" to turn passive mode off. If I don't, I get

421 Service not available, remote server has closed connection
Passive mode refused.  Turning off passive mode.
No control connection for command: Transport endpoint is not connected

Alright. Obviously, passive mode needs to be disabled. I've read the man page a few times and I understand that I need to use -P to specify "active" mode, however from the documentation it seems like this will open a port on the client (my) machine for the data to stream to. Since it's behind a firewall, this won't work.

This tells me that I misunderstand something, because the CLI client works in active mode.

Help me serverfault-kenobi, you're my only hope.


This link explains Active vs Passive very well.

| improve this answer | |

I got it!

The key is to use -P, but you've got to use the "obvious" choice, since you can't open another port and have it connect in.

To quote the documentation:

- make curl pick the same IP address that is already used for the control connection

So the curl command

curl -u username:password -P - -o output.file ftp://whatever/source.file

The -P - was the important part. Essentially it makes curl use the only available connection (the command connection) for transferring data.


| improve this answer | |
  • Without a sniffer to validate the data, I can't be sure, but I think that the "-P" option is only turning passive mode off, just like you said you did in your client. Active mode doesn't use the command connection for transferring data, rather it tells the server to initiate the data connection. The second "-" in "-P -" tells the curl client which IP address to send to the server so the server can initiate the connection. Word of warning - when the client firewall policy changes in the future, you may need to start using PASSIVE mode again. – pcapademic Jun 2 '09 at 21:11

For me - to make it work - I also had to add --disable-eprt as well:

curl --disable-eprt -u username:password -P - ftp://whatever/source.file
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.