skip to content

Why did RFC 2428 add EPRT and EPSV to FTP, and how does a 229 reply differ from a 227 reply?

level: middleimportance: nice to knowfreq 12%

answer

  1. four address bytes are not enough
  2. an address-family number
  3. 229 carries only a port
  4. reuse the control connection's address
  5. EPSV ALL locks it in

basics

~20 s

PORT and 227 hold only a four-byte IPv4 address. RFC 2428's EPRT names an address family and any address, while EPSV's 229 reply carries only a port, so the client reuses the control connection's address.

solid answer

~40 s

RFC 959's `PORT` and `227` have room for exactly four address bytes, so an IPv6-only client cannot use them. RFC 2428 (1998) added two replacements. `EPRT |2|2001:db8::15|50000|` is active mode for any protocol: an address-family number (1 for IPv4, 2 for IPv6), the address as text and the port; the server answers `200`, or `522` listing the families it does support. `EPSV` is passive mode, and its reply MUST be `229 Entering Extended Passive Mode (|||50069|)` — the first two fields are blank and only the port is sent, because the data connection uses the control connection's protocol and address. With no address in the reply, nothing needs rewriting by a NAT device. A client can send `EPSV ALL` to promise it will use no other setup command for the rest of the session.

go deeper

for a junior

Recall that EPRT and EPSV are the extended forms of PORT and PASV, added so FTP can work over IPv6 as well as IPv4.

for a middle

Read a 229 reply and explain why it holds only a port: the client reuses the control connection's protocol and address, so there is no embedded address to get wrong.

for a senior

Know the edges: what a server must refuse after EPSV ALL, why a three-way transfer then needs a new session, and how 522 names the address families a server supports.

for a principal

Weigh designing a failure out against patching it: EPSV removes the embedded address that middleboxes had to rewrite, rather than adding one more device that edits the control channel.

## What PORT and 227 cannot say RFC 959 (1985) moves every data-connection endpoint as six numbers, `h1,h2,h3,h4,p1,p2`: four bytes of IPv4 address and two bytes of port. An IPv6 address is 16 bytes, so an **IPv6-only client** has no way to send `PORT` and cannot use a `227 Entering Passive Mode` reply. **RFC 2428** (1998, Standards Track, "FTP Extensions for IPv6 and NATs") replaces `PORT` and `PASV` with two extended commands that work for any network protocol. ## EPRT: active mode for any address family `EPRT` does what `PORT` does — the client listens and the server connects — but spells the endpoint out: `EPRT <d><net-prt><d><net-addr><d><tcp-port><d>` | Field | Meaning | Example | |---|---|---| | `<d>` | a delimiter, any printable ASCII character; the vertical bar is recommended | `\|` | | `<net-prt>` | an IANA address-family number | `1` = IPv4, `2` = IPv6 | | `<net-addr>` | the address as text | `2001:db8::15` | | `<tcp-port>` | the port as a decimal number | `50000` | So an IPv6 client listening on port 50000 sends `EPRT |2|2001:db8::15|50000|`. A server that accepts it replies `200 Command okay`. A server that does not support the requested protocol replies **`522`**, and RFC 2428 requires the text to list the families it does support in parentheses — for example `522 Network protocol not supported, use (1)`. ## EPSV and the 229 reply `EPSV` is the extended `PASV`: the server listens and the client connects. Its reply **MUST** be **`229`**, in this shape: `229 Entering Extended Passive Mode (|||50069|)` - The parenthesised part has the same layout as an `EPRT` argument, so one parser handles both. - The first two fields — protocol and address — **MUST be blank**. Only the port is filled in. - The data connection uses **the same network protocol and the same address as the control connection**. The client already knows that address: it is the one it connected to on port 21. `EPSV` may also take an argument naming a protocol (`EPSV 2`) when a client needs a specific one; an unsupported protocol gets `522`. ## 227 and 229 side by side | | `227` (reply to `PASV`) | `229` (reply to `EPSV`) | |---|---|---| | Defined in | RFC 959 | RFC 2428 | | Carries an address | yes, four IPv4 bytes | no — fields left blank | | Carries a port | yes, as `p1,p2` | yes, as a decimal number | | Works over IPv6 | no | yes | | Address the client dials | the one in the reply | the control connection's address | Because a `229` carries no address, it has nothing that a NAT device would need to rewrite, and nothing the server can get wrong by advertising an inside address. RFC 2428 says so directly: using `EPSV` "does not require NATs to change the network address" in the traffic. Section 4 of the RFC goes further and says that for transfers between the same two machines that hold the control connection, `EPSV` **MUST** be used. ## EPSV ALL A client can send `EPSV ALL` to announce that, for the rest of the session, it will set up data connections with `EPSV` only: 1. On receipt, the server **MUST reject every other data-connection setup command** — `EPRT`, `PORT`, `PASV` and the rest. 2. A NAT device in the path can then put the connection on a "fast path", because it knows no embedded address will ever need translating. 3. RFC 2428 says a client expecting only two-way transfers SHOULD send it as early as possible. 4. If the client later needs a three-way (server-to-server) transfer, it **MUST start a new FTP session**, since this one can no longer use `PORT` or `EPRT`. ## The IPv6-only client, end to end | # | Direction | Line | |---|---|---| | 1 | C → S | TCP connection to [2001:db8::21] port 21; login | | 2 | C → S | `EPSV` | | 3 | S → C | `229 Entering Extended Passive Mode (\|\|\|50069\|)` | | 4 | C → S | TCP connection to [2001:db8::21] port 50069 | | 5 | C → S | `LIST` | | 6 | S → C | `150 File status okay; about to open data connection`, the listing, then `226 Closing data connection` | Had the client sent `PASV`, the server could only answer with a four-byte IPv4 address in a `227`, which an IPv6-only client cannot use — the gap the extended commands close. ## Misconceptions to avoid - "The `229` reply contains the server's IPv6 address." It contains only the port; the address fields are blank by rule. - "EPRT and EPSV only matter for IPv6." `EPSV` also removes the embedded address that breaks IPv4 FTP through NAT. - "After `EPSV ALL` a client can still fall back to `PASV`." The server must refuse it; a new session is the only way back. - "They are a vendor extension." RFC 2428 is a Standards Track RFC.

  • What must an FTP server do after a client sends EPSV ALL?
    Reject every other data-connection setup command — `EPRT`, `PORT`, `PASV` and the rest — for the remainder of the session; RFC 2428 makes it a MUST. A NAT device can then treat the connection as never needing address translation. A client that later needs a three-way transfer must start a new FTP session.
  • What does a 522 reply to an FTP EPRT command mean?
    The server does not support the network protocol named in `EPRT`. RFC 2428 requires the reply to list, in parentheses, the address-family numbers it does support — for example `522 Network protocol not supported, use (1)` — so a client that offered IPv6 learns the server speaks only IPv4.
  • Why does a 229 reply keep empty fields instead of omitting them?
    RFC 2428 makes the parenthesised part the same layout as an `EPRT` argument, so one parser handles both, and keeps the protocol and address fields as placeholders in case a future response needs them. Today the first two fields MUST be blank and only the port is filled in.

  • An FTP 229 reply contains the server's IPv6 address
  • EPRT and EPSV only matter on IPv6 networks
  • After EPSV ALL a client can still fall back to PASV
  • PORT accepts an IPv6 address written as extra numbers
  • EPRT and EPSV are a vendor extension rather than a standard