Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Networking

Active vs passive FTP: how the data connection works

Active and passive FTP explained: PORT, PASV and EPSV step by step, why NAT breaks active mode, how TLS changes firewall rules, and passive setup for vsftpd.

CloudSat teamNovember 18, 20266 min read
Abstract illustration of two glowing lines between a laptop and a server, one solid and one dashed, crossing a wall
On this pageTwo connections, not one

FTP is older than firewalls, and it shows. Every session uses two TCP connections: one for commands and a fresh one for each directory listing or file transfer. "Active" and "passive" describe who opens that second connection. Get it wrong and you see the classic symptom: the login succeeds, then the directory listing hangs until it times out. This guide walks through both modes at the packet level, shows why passive mode won, and gives working passive settings for common servers.

Two connections, not one

The control connection goes from the client to the server's port 21 and stays open for the whole session. Commands such as USER, PASS, LIST, RETR and STOR travel over it, and the server answers with numbered replies such as 230 for a successful login.

The data connection is opened for each listing and each file, then closed. Its direction is the whole difference between the two modes.

Active mode, step by step

  1. The client connects from a random high port to port 21 on the server and logs in.
  2. The client starts listening on a port of its own and tells the server where to find it: PORT 192,0,2,15,195,80. The first four numbers are its IPv4 address, the last two encode the port.
  3. The server opens the data connection from its port 20 to the client's port 50000.

For IPv6 the client sends EPRT |2|2001:db8::15|50000| instead, with the address family, address and port in plain text.

Active mode made sense when every computer had a public address and no firewall. Today it fails in two ways. The client's firewall usually drops the unexpected inbound connection from the server. And a client behind NAT advertises its private address in the PORT command, so the server tries to connect to an address that does not exist on the internet.

Passive mode, step by step

  1. The control connection opens exactly as before.
  2. The client sends PASV. The server picks a port, starts listening on it, and replies 227 Entering Passive Mode (203,0,113,10,195,80).
  3. The client opens the data connection to 203.0.113.10 on port 50000.

The extended form, EPSV, answers 229 Entering Extended Passive Mode (|||50000|). It carries only a port, and the client reuses the address of the control connection. That works over IPv6 and avoids the problem of a server announcing the wrong address.

Now the client only makes outbound connections, which every home router and office firewall allows. The burden moves to the server: it must accept inbound connections on its passive ports and announce an address the client can actually reach.

Decoding the port numbers

The last two numbers in PORT and 227 replies are the port split into two bytes:

Reply fragment Calculation Port
195,80 195 × 256 + 80 50000
156,64 156 × 256 + 64 40000
0,21 0 × 256 + 21 21

When a client log shows 227 Entering Passive Mode (10,0,0,5,...), the server is announcing a private address, and remote clients will never connect. That single line explains a large share of FTP support tickets.

Active and passive side by side

Active Passive
Data connection opened by Server, toward the client Client, toward the server
Commands PORT, EPRT PASV, EPSV
Server firewall Inbound 21, outbound from 20 Inbound 21 plus the passive range
Client firewall Must accept inbound connections Outbound only
Client behind NAT Usually breaks Works
Default in current clients No Yes

Firewalls, NAT helpers and TLS

Stateful firewalls can follow FTP by reading the control connection and opening data ports on the fly. Linux has the nf_conntrack_ftp helper and Windows Firewall has a stateful FTP filter. Two things undermine that approach. Recent Linux kernels no longer attach the FTP helper to connections automatically, so it has to be enabled with explicit rules. And FTPS encrypts the control connection, so no helper can read the port numbers any more.

The dependable setup therefore ignores helpers entirely: give the server a fixed passive range, open that range explicitly, and set the address the server announces.

Configure passive mode on a Linux server

For vsftpd, add these lines to /etc/vsftpd.conf, along with the paths to your certificate and key in rsa_cert_file and rsa_private_key_file:

pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
pasv_address=203.0.113.10
ssl_enable=YES
force_local_logins_ssl=YES
force_local_data_ssl=YES

ProFTPD uses two directives in proftpd.conf:

PassivePorts 40000 40100
MasqueradeAddress 203.0.113.10

The announced address setting matters only when the server sits behind NAT. On a server whose public address is configured on its own interface, the default answer is already correct. Then open the control port and the range in the host firewall:

sudo ufw allow 21/tcp
sudo ufw allow 40000:40100/tcp
sudo systemctl restart vsftpd

Open the same two entries in any firewall in front of the server. A CloudSat cloud firewall accepts a port range in a single rule, so the passive range is one line. On Windows with IIS, the equivalent settings live in FTP Firewall Support, covered in the guide to running FTPS on Windows.

Choose the mode in the client

  • FileZilla: passive is the default under the FTP connection settings, and each saved site can override it in Transfer Settings.
  • curl: passive by default. --ftp-port - switches to active mode using the same local address as the control connection.
  • lftp: passive by default; set ftp:passive-mode off switches.
  • Windows ftp.exe: active only. Microsoft's own IIS documentation notes that this client does not support passive connections.

Current versions of Chrome and Firefox no longer open ftp:// links at all, so use a dedicated client.

Troubleshoot by symptom

Symptom Likely cause
Login works, listing hangs Passive range blocked, or the server announces a private address
425 Can't open data connection The data connection failed in whichever direction the mode requires
Works without TLS, fails with TLS A firewall helper was doing the work; open the passive range explicitly
Active mode works only on the office network The client's NAT or firewall drops the server's inbound data connection

FAQ

Is passive FTP more secure than active?

No. The mode only decides who opens the data connection. Neither mode encrypts anything. For security, use FTPS (FTP over TLS) or switch to SFTP, which runs over SSH on a single port.

What is port 20 used for?

It is the server's source port for data connections in active mode. Passive mode does not use it, so a passive-only server does not need any rule for port 20.

Why does my client sometimes switch to active mode on its own?

Some clients, FileZilla among them, can fall back to the other mode when a data connection fails. That hides the real problem and produces transfers that work on one network and not on another. Turn the fallback off while you troubleshoot, fix the passive range or the announced address, then leave passive mode as the only mode.

How large should the passive range be?

Each concurrent listing or transfer holds one port while it runs. A range of 100 ports suits a small team; widen it for busy servers and keep every firewall rule in step with the server setting.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.