What is FTP?

File Transfer Protocol (FTP) is the protocol that actually lets you transfer files across an IP network, and it can accomplish this between any two machines that are using it. But FTP isn’t just a protocol; it’s also a program. Operating as a protocol, FTP is used by applications. As a program, it’s employed by users to perform file tasks by hand. FTP also allows for access to both directories and files and can accomplish certain types of directory operations, such as relocating files into different directories.

Screen Shot 2023-01-09 at 5.24.18 PM.png

How does FTP work?

Unless you configure your FTP server differently, you will normally set your command channel to use FTP port 21. The FTP port you'll use for the data channel, on the other hand, can differ depending on which data transfer mode you choose. If you choose the active mode, then the data channel will normally be FTP port 20. But if you choose the passive mode, then the port that will be used will be a random port.

file-2142640810.png

Active Mode FTP

The Active mode can be summarized in two steps.

  1. A user connects from a random port on a file transfer client to FTP port 21 on the server. It sends the PORT command, specifying what client-side port the server should connect to. This port will be used later on for the data channel and is different from the port used in this step for the command channel.
  2. The server connects from port 20 to the client port designated for the data channel. Once the data connection is established, file transfers are then made through these client and server ports.

file-1631228625.png

Passive Mode FTP

In passive mode, the client still initiates a command channel ( control connection) to the server. However, instead of sending the PORT command, it sends the PASV command, which is basically a request for a server port to connect to for data transmission. When the FTP server replies, it indicates what data port number it has opened for the ensuing data transfer.

  1. The client connects from a random port to port 21 on the server and issues PASV command. The server replies, indicating which (random) port it has opened for data transfer.
  2. The client connects from another random port to the random port specified in the server’s response. Once the connection is established, data transfers are made through these client and server ports.

ftp_passive_mode-resized-600-1.png

Active Mode vs Passive Mode FTP: Which Is More Suitable For You?

The above diagrams show how the active and passive modes of the FTP work, for the active mode the second arrow is pointing to the client. that means the client initially specifies which client-side port it has opened up for the data channel, and the server initiates the connection. By contrast, in the passive mode, the second arrow is pointing to the server. Here, the server specifies which server-side port the client should connect to and the client initiates the connection.

In an active mode configuration, the server will attempt to connect to a random client-server port. So chances are, that port wouldn’t be one of the predefined ports. As a result, an attempt to connect to it will be blocked by the firewall and no connection will be established.

active-ftp-with-firewall-resized-600-1.png