I'm trying to connect to an ftp server and do numerous things from a batch file. However, on any new computer, even after allowing ports 20 and 21 in and out, it hangs when I run any command such as ls or cd with 200 PORT command successful. It logs in fine but once I try and do something it hangs. If I turn off the firewall it works fine, however this is not ideal. What other ports or settings must I change?
1 Answer
Port 21 is the control port of FTP where the FTP client connects to. Port 20 is the source port of the data connection where the FTP server connects from when using active mode (i.e. PORT command). This means, if you really want to allow FTP active mode you need to allow connections originating from port 20 instead of allowing connection to port 20.
It is much better to not use active mode in the first place. With active mode the server connects to the client which is a nightmare if firewalls are involved and even worse if NAT is involved - i.e. practically with all internet access out of a local network from behind a typical SoHo router.
Use instead passive mode which is designed to work in scenarios where the client is behind a firewall and/or router doing NAT. If on the other hand you have both client and server behind firewall or NAT it is terribly hard or even impossible (depending on firewall and router) to establish a data connection.
In other words: FTP must die. If possible use protocols like SFTP (not FTPS) or HTTP(S) to transfer data since these protocols don't cause the nightmarish problems one gets with FTP.
3