Port 21 (FTP)
Key facts
- Port
- 21
- Protocols
- TCP
- Range
- System port (Well-Known), 0-1023
- IANA service name
- ftp
IANA assigns ports in this range to well-known services, under RFC 6335.
About port 21
Port 21 is the control port of FTP (File Transfer Protocol), the long-standing protocol for moving files between a computer and a server, over TCP. Login details and commands go through port 21, while the files themselves travel over a separate data connection.
The protocol is defined in RFC 959, and IANA registers port 21 for the ftp service.
What port 21 is used for
FTP is mainly used to upload website files to a server and download them, with FTP clients or code editors that support direct upload. The data connection is opened in one of two modes, and there is also an encrypted version:
- Passive mode: the client also opens the data connection to the server, on a port from a range set on the server. This is the common mode today, because it works better behind routers and home firewalls.
- Active mode: the server opens the data connection to the client's computer, from port 20. This mode is often blocked on the client side.
- FTPS: an extension that encrypts the connection with TLS. With the common method, Explicit FTPS, encryption starts inside the connection to port 21. With the older method, Implicit FTPS, the connection is encrypted from the start and goes to port 990.
SFTP, on the other hand, is a completely different protocol: it runs over SSH, usually on port 22, and doesn't use port 21.
Port 21 in the firewall
On a server that provides FTP, open TCP port 21, plus the Passive mode port range set in the FTP server software. Opening only port 21 is the common reason a login succeeds but the file list doesn't load.
When only you or a few developers connect, we recommend allowing access only from your IP addresses, for example:
- UFW:
ufw allow from 203.0.113.10 to any port 21 proto tcp - firewalld:
firewall-cmd --permanent --add-service=ftpand thenfirewall-cmd --reload
A server that doesn't provide FTP doesn't need port 21 open at all.
Risks and security
With plain FTP, the username, password, and files cross the network unencrypted. That's why we recommend connecting over FTPS or SFTP, which encrypt the whole connection, and keeping plain FTP for an internal network only, or not using it at all.
- Use a strong, unique password for each FTP account, and give each account access only to the folder it needs.
- Delete FTP accounts that are no longer in use, such as a temporary account opened for an outside developer.
- Limit access to known IP addresses when possible, and run a tool such as fail2ban, which temporarily blocks addresses that make repeated failed login attempts.
- Don't allow anonymous logins on a server used for a website.
Commands to check and configure
-
ss -tlnp | grep ':21 'Checks whether any service is listening on port 21 on the server, and which process it is (requires root).
-
nc -zv ftp.example.com 21Checks from your computer whether port 21 on the server is open and reachable.
-
openssl s_client -connect ftp.example.com:21 -starttls ftpChecks whether the server supports Explicit FTPS, and shows its certificate details.
-
ufw allow from 203.0.113.10 to any port 21 proto tcpAllows access to port 21 only from the given IP address (UFW).
-
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. Then run firewall-cmd --reload.
-
firewall-cmd --permanent --add-port=40000-40100/tcpOpens an example port range for Passive mode in firewalld.
Port 21 in the IANA registry
| Port | Protocol | Service | IANA registry description |
|---|---|---|---|
| 21 | SCTP | ftp | FTP |
| 21 | TCP | ftp | File Transfer Protocol [Control] |
| 21 | UDP | ftp | File Transfer Protocol [Control] |
Data source: IANA Service Name and Transport Protocol Port Number Registry (opens in a new tab)
Port 21 FAQ
What's the difference between FTP, FTPS, and SFTP?
FTP is the original protocol, and it transfers data without encryption. FTPS is FTP with TLS encryption, and it still uses port 21 (or port 990, with the older Implicit FTPS method). SFTP is a different protocol that runs over SSH, usually on port 22, and encrypts the whole connection from the start.
Why does my FTP login work but the file list doesn't load?
In most cases, the data connection is being blocked. Port 21 carries only commands, while the file list and the files themselves travel over a separate connection. Make sure your FTP client is set to Passive mode and that the Passive mode port range is open in the server's firewall.
Can I upload files to my website securely?
Yes. We recommend connecting over FTPS (the "FTP over TLS" option in your FTP client) or over SFTP, when the server allows it. Both options encrypt your password and files on the way to the server, and popular FTP clients support both.
Can FTP run on a different port?
Yes. You can set the FTP server to listen on a different port, and enter that port number in your FTP client when you connect. Changing the port cuts down on automated scans and log noise, but it doesn't replace encryption, strong passwords, and limiting access by IP address.