Port 20 (FTP Data)
Key facts
- Port
- 20
- Protocols
- TCP
- Range
- System port (Well-Known), 0-1023
- IANA service name
- ftp-data
IANA assigns ports in this range to well-known services, under RFC 6335.
About port 20
Port 20 is the FTP data port in Active mode, used to transfer files and directory listings between the server and the client's computer, over TCP. FTP uses two separate connections: commands and login details go through port 21, while the data travels over a separate data connection. In Active mode, the server opens the data connection to the client's computer, and port 20 is the source port of that connection.
RFC 959, which defines FTP, sets the server's data port as the port next to the control port, that is, 20. In the IANA port registry, port 20 is registered for the ftp-data service.
What port 20 is used for
Port 20 is used only when the FTP connection runs in Active mode. FTP has two ways to open the data connection:
- Active mode: the client tells the server which port on its computer to connect to, and the server opens the data connection from port 20 to that port.
- Passive mode: the server listens on a port from a range set on it, and the client opens the data connection to it as well. In this mode, port 20 isn't used at all.
Most FTP clients use Passive mode by default today, because it works better behind home routers and firewalls. That's why port 20 shows up mainly with older equipment and with connections explicitly set to Active mode.
Port 20 in the firewall
An FTP server doesn't need port 20 open to incoming connections. In Active mode, the server is the one that creates the connection from port 20, so you only need to make sure outgoing connections from the server aren't blocked.
On an FTP server, open port 21 and the Passive mode port range, as set in the FTP server software:
- UFW:
ufw allow 21/tcpandufw allow 40000:40100/tcp - firewalld:
firewall-cmd --permanent --add-service=ftpandfirewall-cmd --permanent --add-port=40000-40100/tcp
In Active mode, the client's computer has to accept an incoming connection from the server. Home routers and firewalls on the computer usually block such a connection, and that's the main reason FTP connections in Active mode fail.
Risks and security
Port 20 itself isn't open to incoming connections, so the main risk relates to FTP as a whole: with plain FTP, login details and files cross the network unencrypted.
- Prefer SFTP, which runs over SSH in a single encrypted connection, or FTP with TLS encryption (FTPS).
- Use Passive mode, and set a small, fixed port range on the server, so you open only what's needed in the firewall.
- Don't open wide port ranges in the firewall just to make Active mode work.
- A server that doesn't provide FTP doesn't need any rule for ports 20 and 21.
Commands to check and configure
-
ss -tn '( sport = :20 )'Shows active data connections opened from port 20, that is, FTP transfers in Active mode.
-
tcpdump -ni any tcp port 20Shows traffic on port 20 in real time, to see whether the server opens data connections in Active mode (requires root).
-
curl -P - -u user ftp://ftp.example.com/Connects to an FTP server in Active mode and shows the file list. The -P - option asks the server to open the data connection to your computer.
-
curl -u user ftp://ftp.example.com/Connects the same way in Passive mode, curl's default, for comparison with Active mode.
-
ufw allow 40000:40100/tcpOpens an example port range for Passive mode (UFW). Match the range to the one set on the FTP server.
-
firewall-cmd --permanent --add-service=ftpOpens the FTP service in firewalld (port 21). Then run firewall-cmd --reload.
-
firewall-cmd --permanent --add-port=40000-40100/tcpOpens an example port range for Passive mode in firewalld.
Port 20 in the IANA registry
| Port | Protocol | Service | IANA registry description |
|---|---|---|---|
| 20 | SCTP | ftp-data | FTP |
| 20 | TCP | ftp-data | File Transfer [Default Data] |
| 20 | UDP | ftp-data | File Transfer [Default Data] |
Data source: IANA Service Name and Transport Protocol Port Number Registry (opens in a new tab)
Port 20 FAQ
What's the difference between Active mode and Passive mode in FTP?
In Active mode, the server opens the data connection from port 20 to your computer. In Passive mode, your computer opens the data connection to the server, on a port from a range set on the server. Passive mode works better behind routers and firewalls, which is why it's the default in most FTP clients.
Do I need to open port 20 in the server's firewall?
No. In Active mode, the server creates the connection from port 20, and the firewall only needs to allow outgoing connections. On an FTP server, you open port 21 and the Passive mode port range.
Why does my FTP login work but the file list doesn't load?
In most cases, the data connection is being blocked. When the client is set to Active mode, the router or the firewall on your computer blocks the connection from the server. Switch your FTP client to Passive mode, and make sure the Passive mode port range is open in the server's firewall.
Does SFTP use port 20?
No. SFTP runs over SSH, usually on port 22, and carries commands and files over the same encrypted connection. So it doesn't need a separate data port or a port range, and it's easier to set up in the firewall.