Networking

FTP — File Transfer Protocol

Nearly every other protocol on this domain uses one TCP connection for everything. FTP, one of the internet's oldest protocols, does something different: it splits a session into a control connection (commands) and a separate data connection (the actual file bytes) — a design choice from an era before anyone had thought through what that would do to firewalls and NAT decades later.

Quick reference
What it is
A file-transfer protocol using two separate TCP connections — one for commands, one for the actual file data.
Mental model
A phone call (the control connection, stays open, you give instructions on it) plus a separate delivery truck (the data connection, opened fresh for each file).
Key numbers
Port 21 for control; port 20 or a dynamically negotiated port for data, depending on mode.
Reach for it when
Rarely for new systems today — SFTP (over SSH) or plain HTTPS uploads are the modern default. Still shows up in legacy industrial and manufacturing tooling.

Two channels, one session

The client connects to the server's control port (21) and sends plain-text commands — USER, PASS, RETR filename (download), STOR filename (upload). The control connection stays open for the whole session, but it never carries file bytes itself — every actual file transfer opens a brand new, separate TCP connection just for that transfer's data.

Active vs. passive mode

Who opens that second, data connection is the single most confusing part of FTP, and the direct consequence of the protocol predating NAT and modern firewalls by decades.

Active mode
The server initiates the data connection back to the client, on a port the client told it to use. This breaks immediately if the client is behind NAT or a firewall — the server is trying to open an unsolicited inbound connection to a machine that, from the internet's point of view, doesn't have a directly reachable address at all.
Passive mode
The client initiates both connections — it asks the server "which port should I use for data," and the server picks one and waits. This works through client-side NAT, which is why passive mode is the practical default almost everywhere today.

Passive mode moves the problem rather than eliminating it: now the server needs a range of ports open and reachable for incoming data connections — a real firewall configuration detail anyone running an FTP server still has to handle.

Why FTP is increasingly legacy

Plain FTP sends everything — including the username and password in the initial handshake — completely unencrypted, the same fundamental problem telnet had for remote shells. Two different fixes emerged, with confusingly similar names:

In practice, SFTP has mostly won for new systems, precisely because it avoids the dual-connection firewall/NAT problem entirely.

Real-world applications

Gotchas

Field notes