Time to Read

3 minutes

What is Active FTP?

Active FTP (File Transfer Protocol) is one of the two modes of operation for FTP connections, the other being Passive FTP. In Active FTP, the client initiates the control connection to the server, but the server actively establishes the data connection back to the client for transferring files. This mode of operation requires the server to open a port on its side for data connection, which can sometimes cause issues with firewalls and NAT devices.

Here’s how Active FTP works with an example:

  1. Client Sends Command:
    • The FTP client initiates a connection to the FTP server on port 21 (the default control connection port) using the TCP protocol.
    • The client sends commands such as USER, PASS, and TYPE to authenticate and specify file transfer settings to the server.
  2. Server Responds:
    • The FTP server acknowledges the commands sent by the client and responds with numeric codes and optional human-readable messages.
    • Once authenticated, the server awaits the client’s file transfer commands.
  3. Client Requests File Transfer:
    • When the client requests to transfer a file (e.g., using the RETR command to retrieve a file from the server), the server acknowledges the command and prepares to establish a data connection.
  4. Server Initiates Data Connection:
    • In Active FTP mode, after receiving the file transfer request, the FTP server initiates a data connection back to the client.
    • The server selects a port on its side (typically port 20) for the data connection and sends a PORT command to the client, specifying the IP address and port number where the client should listen for the data connection.
  5. Client Opens Data Connection:
    • Upon receiving the PORT command from the server, the client opens a new TCP connection on the specified port to listen for the incoming data connection from the server.
    • The client sends an acknowledgment to the server, indicating that it’s ready to receive the data connection.
  6. Data Transfer:
    • Once the data connection is established, the server begins transferring the requested file over the data connection to the client.
    • Data is transmitted in chunks, and the client acknowledges the receipt of each chunk.
  7. File Transfer Completion:
    • After transferring the file, the server sends a success response to the client, indicating that the file transfer is complete.
    • The data connection is closed, and the control connection remains open for further commands or file transfers.

An example with Diagram:

Explanation of the diagram:

  1. Control Connection Establishment:
    • The FTP client initiates a TCP connection to the FTP server on port 21 for the control connection.
    • The client sends FTP commands (e.g., USER, PASS) for authentication and configuration.
  2. Data Connection Establishment (Active FTP):
    • After receiving a file transfer request, the FTP server initiates a data connection back to the client on port 20.
    • The server sends a PORT command to the client, specifying the IP address and port number for the data connection.
  3. Data Transfer:
    • The FTP server begins transferring the requested file over the data connection to the client.
    • Data packets are transmitted from the server to the client.
  4. Data Transfer Acknowledgment:
    • The client acknowledges the receipt of data packets, ensuring reliable transmission.
  5. Transfer Completion:
    • After completing the file transfer, the server sends a success response to the client.
    • The data connection is closed, and the control connection remains open for further commands or file transfers.

Active FTP can encounter issues with firewalls and NAT devices because the server initiates the data connection back to the client, which requires the server to open a port for incoming connections. If the client is behind a firewall or NAT device, it may block incoming connections, causing the data connection to fail. Passive FTP, on the other hand, alleviates these issues by having the client establish both the control and data connections to the server.


Discover more from Sanchit Gurukul

Subscribe to get the latest posts to your email.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Discover more from Sanchit Gurukul

Subscribe now to keep reading and get access to the full archive.

Continue reading