Windows – FTP “425 Can’t open data connection” only happens when using command prompt

command lineftpwindows

All of my computer are behind a single router. I have a FileZilla server running on one of them. I am trying to automate an upload to the server using a batch script and Window's built-in ftp.exe. I have set up a dynamic DNS service to be able to access my server from outside the router and I have set up port forwarding in the router to my server. I can connect and transfer just fine using Google Chrome, Windows Explorer, and the FileZilla client. However, whenever I try using ftp.exe (either manually or in batch script) I can connect to the server but if I try doing anything that would open a data connection (LIST, STOR, or RETR) I get the following error: 425 Can't open data connection. I have allowed ftp.exe in both computer's firewalls. Any ideas what is going on or how I could fix it? I don't need to use ftp.exe if anyone knows of a portable independent (just an exe with no other files) command line client.

EDIT I know that my ISP blocks many ports including 21 and several others in that range. This is all set up on port 2121, with the passive ports set up to be 2122-2142, all of these have been forwarded in the router. Perhaps ftp.exe will only use a certain port for data connection, which my ISP blocked? If so how would I change this?

Best Answer

Regular active FTP uses a separate server-initiated data connection for transfers and only uses the regular port 21 connection as the control channel. When the client is behind a firewall, however, the firewall is likely to block this connection. I'm guessing Chrome, Explorer, FireZilla, etc. are smart enough to try passive mode, in which the original client-initiated connection is used as both the control and data channel.

It appears that Windows' default CLI FTP client doesn't support passive mode. So you'll need to switch to NcFTP. Alternatively, and I think probably the better option, is just to use SFTP instead. FTP is insecure and really only to be used on LANs. SFTP is fully encrypted and also only uses a single channel for data and commands. If you need a CLI SFTP client, PSFTP is a good option.