File Transfer Protocol (FTP) is a network protocol used to transfer data from one computer. In order to download and upload files to an FTP site, you need to connect using an FTP client/server.
FTP runs exclusively over TCP and listens on port 21 (command port) by default. Data is transferred across a separate data channel, but this port varies dependent on the FTP mode being used.
Generally there are 2 modes for FTP,
- Active mode
- Passive mode (PASV)
In Active mode the client connects to the FTP Servers command port (21) from a random high port. The clients data port then starts listening on a port, which is one greater than the random high port previously selected, and informs the server using the PORT command.
The server then connects to the clients data port from a source port of 20 (or the command port minus 1).
In order to stop the server initiating a data connection to the client, passive FTP or PASV was created. With passive mode the client initiates both connections to the server.
This resolves many of the firewall issues associated with Active FTP and the incoming data connections from the FTP server.
When opening a Passive connection the client opens two random ports locally. The first port is used to connect to the servers command port on port 21.
The client then issues the PASV command. The server then opens a random high port as the data port and informs the client. The client then connects to this port.
Since most of port allocations in Active vs Passive FTP connections is “behind the scenes” …you will not generally know what setting (Active vs Passive) is appropriate. So often it is best to just experiment with enabling or disabling PASV mode connection settings in your FTP connection in your FTP client software.