Why is FTP harder to let through a stateful firewall than SSH or HTTPS, and what must the firewall allow for active and passive transfers?
answer
- more than one connection
- ports negotiated in-band
- who opens the data connection
- helper reads the control channel
basics
~20 sFTP sends files over separate data connections whose ports, and often addresses, are negotiated inside the control connection on port 21. A firewall must either open a whole port range or read that conversation to admit each one.
solid answer
~50 sSSH and HTTPS each need one rule: a single TCP port, one connection. FTP keeps commands on a control connection to port 21 but moves every file and listing over a **separate data connection** on a port agreed at run time. In **active** mode the server dials the client from port 20, so the client side must accept an unsolicited inbound connection to whatever port its `PORT` command named. In **passive** mode the client dials the server, so the server side must accept inbound connections on the port its `227 Entering Passive Mode` reply named, which is any high port unless the server is pinned to a fixed range. A firewall therefore has two choices: open a standing range, or run an **FTP helper** that reads `PORT` and `227` on the control channel and opens a pinhole for just that one data connection.
go deeper
Recall the two connections: control on port 21 and a new data connection per transfer or listing, and that its port is agreed at run time, so one firewall rule is not enough.
Explain which side dials in active and passive mode, which firewall faces the inbound connection in each, and how an FTP helper reads PORT and 227 to open a single pinhole.
Show you would pin the passive range, open exactly that range plus 21, and not rely on a helper that TLS will blind; know how to read a firewall log for dropped data connections.
Weigh a standing open range against helper-dependent inspection, and argue when the operational cost of FTP's port model justifies moving partners to a single-port protocol.
## One service, many connections Most protocols a firewall administrator meets are one connection on one well-known port: SSH on 22, HTTPS on 443. A rule such as "allow TCP 443 to the web server" describes the whole service, and a **stateful firewall** (one that tracks connections and lets reply packets of an allowed connection back through) needs nothing else. FTP (RFC 959) splits its work in two: - a **control connection** from the client to the server's TCP port 21, carrying commands and numbered replies; - a **data connection** for every file transfer and every directory listing, opened afresh each time on a port the two sides agree on over the control connection. The data connection's port, and in the classic commands its IP address too, travel as ASCII text inside the control connection's payload. A firewall that looks only at packet headers sees an unrelated new connection to an unpredictable port and, correctly by its own rules, drops it. ## What each mode asks of the firewall Who dials whom decides which firewall faces the new inbound connection. | Mode | Who opens the data connection | Unsolicited inbound connection lands at | Rule needed without a helper | |---|---|---|---| | Active (`PORT`, `EPRT`) | The server, from its port 20 | The client, on the port it announced | Inbound to the client's ephemeral ports, which is unacceptable on almost any client network | | Passive (`PASV`, `EPSV`) | The client | The server, on the port in its reply | Inbound to the server's passive port range | Two consequences follow: - **Active mode is the client network's problem.** Opening "any inbound TCP to any desktop" defeats the point of the client-side firewall, so active mode rarely survives a client behind a firewall or a NAT. - **Passive mode is the server operator's problem.** RFC 1579 ("Firewall-Friendly FTP") recommended passive mode for exactly this reason: the data connection becomes an outgoing call from the client's side, which client firewalls handle easily. The server side, however, must now admit inbound connections to whatever port the server picks, and left alone a server may pick any port above 1023. ## The three ways sites cope 1. **Pin and open a range.** The server is configured to use only, say, ports 60000 to 60199 for passive data connections, and the firewall in front of it allows exactly that range plus port 21. Simple and predictable; the cost is a standing open range on the server. 2. **Run an FTP helper.** Stateful firewalls and NAT devices commonly carry an FTP **application-level gateway** (ALG), also called a helper. It parses the control connection, reads each `PORT`, `EPRT`, `227` or `229`, and creates a short-lived **expected connection**, or pinhole, that admits only the one data connection those messages announced. Nothing is open between transfers. 3. **Avoid the problem.** Protocols that carry files inside a single connection need one rule; that is one reason many sites moved file exchange to SFTP over SSH's single port 22. ## Why helpers are fragile The helper approach depends on the firewall being able to read the control connection: - it must see the whole `PORT` line or `227` reply, so unusual segmentation can defeat it; - it must understand every variant in use, including the extended commands added for IPv6; - once the control connection is encrypted with TLS (explicit FTPS), the helper sees ciphertext and can open nothing. The last point is why switching a working FTP service to FTPS so often breaks it at the firewall, and why serious FTPS deployments rely on a pinned, statically opened passive range rather than on a helper. ## What a good answer sounds like A strong candidate names the two connections, says which side dials in each mode, states the rule each mode needs, and explains both mitigations: a fixed passive range, or a helper that reads the control channel. Mentioning that encryption blinds the helper shows production experience. When a NAT sits on the path as well, the problem grows: the address written inside `PORT` and `227` may be a private one that the outside cannot reach, which is a separate failure from the firewall rule and needs its own fix.
- Why does the server side not need a special rule for active-mode data connections?In active mode the server opens the data connection outbound, from its port 20 to the client. A stateful firewall in front of the server normally allows outbound connections and their replies, so nothing inbound has to be opened at the server. The difficulty lands on the client's network instead, which must accept an unsolicited inbound connection to the port the client announced.
- What does an FTP helper open, and for how long?It opens an expected-connection entry for the single data connection a `PORT`, `EPRT`, `227` or `229` message just announced: the named port, from the peer of that control connection. Once that data connection is established it is tracked like any other connection, and an expectation that is never used is dropped, so no standing range is exposed between transfers.
- FTP needs only port 21 open because files travel on the control connection
- Passive mode needs port 20 open inbound on the server
- Active mode is the firewall-friendly mode because the server does the dialling
- A stateful firewall automatically understands FTP without any helper or open range
- Encrypting the control channel makes FTP easier for firewalls to handle