Firewall – what ports do I open on windows server 2008 firewall for command line ftp to work

firewallftpwindows-server-2008

I thought if I opened ports 20 and 21 it would work. Instead I'm able to connect and change directories but whenI try a 'dir' for example, I get "Could not open data connection to port XXXXX" with the port number varying. If I just turn off the firewall everything works fine. Is there some massive port range I have to allow for this to work?

Best Answer

When creating the FTP site in IIS you have the choice of which dynamic ports to use. Whatever ports are set there need to be open in the firewall.

Or, you need to use an FTP client that supports PASV mode, which forces all transfers over the FTP port. But the command line from Microsoft does not support that.

The other option that you have would be to enable Stateful FTP inspection of the firewall. After opening the FTP (21) port, issue the following command on the server at the command line:

netsh advfirewall set global StatefulFtp enable

I believe that only works on Vista, Windows 7, and 2K8 "servers."