File Transfer Protocol (FTP)
FTP is the standard protocol for transferring files between computers over a network. It follows a client-server model where a user connects to a remote server to upload, download, and manage files. What makes FTP distinct from other protocols is its use of two separate connections: one for commands and one for actual data transfer.
Purpose of FTP
FTP solves a straightforward problem: moving files between machines that may be running different operating systems or file systems. The protocol handles the translation details so you don't have to.
A few key characteristics define how FTP works:
- It uses a client-server model where the client initiates a connection, sends commands, and the server responds and performs the requested actions.
- It establishes two separate TCP connections: a control connection (port 21) for sending commands and receiving responses, and a data connection (port 20 in active mode) for the actual file transfers and directory listings.
- It provides reliable transfer by running over TCP, which guarantees delivery and correct ordering of data.
Common FTP client software includes FileZilla, WinSCP, and command-line FTP tools built into most operating systems.

Client-Server Architecture in FTP
The FTP client is the program you run on your local machine. It connects to the server, authenticates with a username and password, and then sends commands to browse directories, list files, and initiate transfers.
The FTP server listens for incoming connections on port 21. Once a client connects, the server authenticates the user, checks permissions, and then executes whatever commands the client sends. Server software examples include vsftpd, ProFTPD, and Microsoft IIS FTP server.
The separation of control and data connections is worth understanding clearly. The control connection stays open for the entire session, carrying your commands (RETR, STOR, etc.) and the server's reply codes. The data connection opens and closes as needed, each time a file transfer or directory listing occurs. This two-connection design is one of the things that makes FTP behave differently from HTTP, which multiplexes everything over a single connection.

Active vs. Passive FTP Modes
FTP has two modes for establishing the data connection, and the difference comes down to who initiates that second connection.
Active mode works like this:
- The client opens a random high-numbered port and sends that port number to the server using the
PORTcommand. - The server then initiates the data connection from its port 20 to the client's specified port.
- The problem: firewalls and NAT devices on the client side often block this incoming connection from the server, since it looks like an unsolicited inbound request.
Passive mode flips the direction:
- The client sends a
PASVcommand to the server. - The server opens a random high-numbered port and replies with its IP address and that port number.
- The client then initiates the data connection to the server's specified port.
- Since the client initiates both the control and data connections, firewalls and NAT on the client side don't cause problems.
Passive mode is far more commonly used today because most clients sit behind firewalls or NAT routers that would block active mode's inbound data connection.
Common FTP Commands
FTP commands are sent as plain text over the control connection. Here are the ones you need to know:
| Command | Function |
|---|---|
USER | Sends the username to the server for authentication |
PASS | Sends the password (sent after USER) |
PWD | Prints the current working directory on the server |
CWD | Changes the current directory on the server |
LIST | Retrieves a list of files and directories in the current directory (sent over the data connection) |
RETR | Downloads a file from the server to the local machine |
STOR | Uploads a file from the local machine to the server |
DELE | Deletes a file on the server |
MKD | Creates a new directory on the server |
RMD | Removes a directory on the server |
QUIT | Terminates the session and closes the control connection |
Notice that LIST and RETR/STOR all require a data connection to be established first. The command itself travels over the control connection, but the actual file content or listing travels over the data connection. Commands like PWD, CWD, and QUIT only use the control connection since they don't transfer file data.
The server responds to each command with a three-digit reply code (for example, 200 for success, 530 for authentication failure). These codes follow a pattern: 2xx means success, 3xx means the server needs more information, 4xx and 5xx indicate errors.