File Transfer Protocol (FTP): Control vs Data Connections and How FTP Works
File Transfer Protocol (FTP ) works by using two separate TCP connections between a client and server: a control connection for commands and replies, and a data connection for the actual file contents. This separation allows the client to exchange control information (e.g., login, directory listing commands) while the transfer itself happens over a distinct channel.
Below is a neat high-level diagram showing the typical behavior for a single file transfer where the client sends FTP commands on the control channel, and the server opens/receives a new connection for the data channel.
Key ideas
- Control connection carries commands like
USER,PASS,RETR, and reply codes like150and226. - Data connection is created separately for each transfer (e.g., for
RETRorSTOR). - FTP uses a command-reply model on the control channel; the data channel exists only when a transfer is taking place.
Footnotes
-
RFC 959: File Transfer Protocol (FTP) - Defines FTP operation including the separation of control and data connections and the command/reply model. ↩ ↩2 ↩3 ↩4
Working of FTP for a File Download (RETR)
- 1Step 1
Client opens a TCP connection to the FTP server’s control port, and the server sends an initial greeting reply (e.g., code 220).
- 2Step 2
Client sends
USERandPASScommands over the control connection; server replies with status codes indicating whether the login is successful. - 3Step 3
Client and server determine how the data connection will be created (commonly by client sending
PORTfor active mode or requestingPASVfor passive mode). - 4Step 4
Client sends
RETR filenameover the control connection. - 5Step 5
Server sends an intermediate reply (commonly 150-series) indicating the data connection is being opened/started.
- 6Step 6
A new TCP connection is established specifically for the data transfer (this is distinct from the already-established control connection).
- 7Step 7
Client and server exchange the file contents over the data connection until completion.
- 8Step 8
Server sends a final completion reply over the control connection (commonly 226-series), and the data connection is closed for that transfer.
Control Connection in FTP
The control connection is the “signaling channel” for FTP. On this connection, FTP uses an ordered exchange of commands and numeric replies, allowing the server to report the state of the session and of transfers (e.g., permission checks, errors, and readiness).
Common properties:
- It is established once per FTP session (typically client connects and stays connected during the session).
- It carries:
- It coordinates creation of the data connection, but does not carry file bytes.
Control connection lifecycle (conceptual)
Footnotes
-
RFC 959: File Transfer Protocol (FTP) - Defines FTP operation including the separation of control and data connections and the command/reply model. ↩
Data Connection in FTP
The data connection is used only when transferring data such as file contents or directory listings. Unlike the control channel, the data connection is typically created per transfer (or at least per transaction), which enables the protocol to keep control signaling responsive while the bulk transfer happens.
Conceptually:
- The control channel tells both sides a transfer is about to happen.
- The data connection provides the bulk pipe for bytes.
Why separate connections?
Separating signaling from payload helps FTP remain structured:
- Control messages (commands/replies) remain available during transfer coordination.
- The bulk transfer uses a connection suited for streaming file bytes.
Footnotes
-
RFC 959: File Transfer Protocol (FTP) - Defines FTP operation including the separation of control and data connections and the command/reply model. ↩
Active vs Passive Modes (How the data connection is created)
FTP must create a new TCP connection for the data channel. The method used depends on whether the client uses active or passive mode.
Active mode (high level)
- Client tells the server where to connect for the data channel (e.g., via
PORTcommand). - Server then connects back to the client’s indicated address/port to start the data transfer.
Passive mode (high level)
- Client sends
PASVand the server responds with an address/port where it is listening for data. - Client then connects to the server’s provided address/port for the data transfer.
Visual comparison
Footnotes
-
RFC 959: File Transfer Protocol (FTP) - Defines FTP operation including the separation of control and data connections and the command/reply model. ↩ ↩2
Pro Tip
When you see 150 on the control connection, it usually means the server has started preparing/opening the data connection; the actual bytes begin on the data channel afterward.
Common Misconception
FTP does not send file contents on the control connection. File bytes always go over the separate data connection created for that transfer.
Control vs Data Connection Roles in FTP
Relative emphasis: commands/replies are control-channel; file bytes are data-channel.
Concept Checkpoints
FTP Transfer Timeline (Single RETR)
Control connection setup
T0Client connects; server sends greeting."
Authentication / session commands
T1Client sends login commands; server replies."
Data connection mode negotiation
T2Client uses PORT (active) or PASV (passive)."
Transfer command
T3Client issues RETR (download)."
Data channel established
T4A new TCP connection is created for file bytes."
File bytes transferred
T5Bulk data flows over the data connection."
Transfer completion
T6Server sends completion reply on control connection."
Knowledge Check
In FTP, where are file contents transferred during a RETR (download)?