ByteScope

21

Port 21 · FTP

TCPIANA assignedFile transfer

FTP's control connection — the port that carries the commands and the numbered replies, while the files themselves move over a second connection on a port nobody told your firewall about.

Find what is using port 21

Run the line for your platform. Each one names the process holding the port and the address it bound to, which is usually the whole answer.

Check it from outside the machine

`nmap -Pn -p 21 files.example.com` asks the only question that matters from outside the host, and `-Pn` skips host discovery so a machine that ignores pings still gets scanned. Nmap's own definitions decide what the answer means: `open` is an application actively accepting connections on that port; `closed` is a reachable port that answered, with no application listening on it; `filtered` means packet filtering stopped the probe from reaching the port, so nmap cannot tell which of the other two it would have been. Add `--reason` to see what decided it — a reset from a closed port against silence from a filtered one — and `-sV` to have nmap read the `220` greeting, which usually names the daemon and its version. One caveat specific to this port: the scan says nothing about the data connection, because a passive transfer uses a high port this scan never touches. `open` on 21 and a download that dies at zero bytes are perfectly consistent findings. Scan only hosts you are responsible for.

Why a connection to 21 fails

What you seeWhat it means
ftp: connect: Connection refusedThe packet reached the host and its kernel answered with a reset, because no process holds port 21. The daemon is stopped, it failed during startup, or it is bound to an address that does not include the one you dialled. Run the probe for your platform on the server, not on your laptop, and read the bind address rather than only confirming that a row exists.
The client sits silent for tens of seconds, then reports Connection timed outNothing answered at all. A packet filter is dropping the SYN without replying — a cloud security group, a host firewall, or a network ACL between you and the server. A refusal comes back instantly and a drop makes you wait, so the delay itself is the diagnosis. Confirm from outside with `nmap --reason`: `filtered` is the drop, `closed` is the refusal.
425 Can't open data connectionPort 21 is fine — you are logged in and the server accepted the command, which is why you got a numbered reply at all. What failed is the second connection. In passive mode the server told you a high port and your firewall would not let you out to it, or the server's own passive range is not open inbound. In active mode the server tried to dial back to your client and something in between blocked it. Switch modes and see which one works: most clients toggle with `passive`, and `curl` uses passive unless you pass `-P -`.
500 Illegal PORT commandThe server is refusing active mode outright, which many now do because the callback is a well-known abuse vector. Use passive mode. The same shape appears when a NAT device rewrites the address inside the `PORT` command and the server sees an address that does not match the control connection it is talking to, which servers reject on purpose.
227 Entering Passive Mode reports an address you cannot route toA server behind NAT that has not been told its public address advertises its private one, so the client dutifully tries to open a data connection to something like 10.0.0.5 and hangs. The fix is on the server: give it the external address to advertise, or use the extended `EPSV` reply, which returns only a port and reuses the control connection's address.
530 Login incorrectNothing here is a port problem. The control connection was established and the server read your credentials before rejecting them. Either the account or password is wrong, or the account exists but is denied FTP specifically — a shell of `/usr/sbin/nologin`, a name listed in the server's deny file, or a configuration that only permits chrooted virtual users.
500 OOPS: could not bind listening IPv4 socket / bind: Address already in use`EADDRINUSE`: something already holds the socket, and the daemon exits during startup rather than later. Usually a second FTP server from a different package, or a container publishing 21 on the host. Name the owner with the probe above before killing anything, and if the port frees itself a minute or two later the previous process left sockets in `TIME_WAIT` and nothing needed killing.
bind: Permission denied while starting the server on 21This one really is the privileged-port rule: on Unix-like systems ports below 1024 need root, and 21 is one of them. Start the daemon through the init system as root, grant the binary `CAP_NET_BIND_SERVICE` on Linux, or listen high and redirect. On SELinux or AppArmor hosts the same message can also come from the policy refusing the bind for that particular binary, so check the audit log before assuming it is the 1024 rule.

What runs on port 21

IANA assigns 21 to `ftp`, the File Transfer Protocol control connection defined by RFC 959, and registers the neighbouring 20 as `ftp-data`. Both TCP and UDP appear in the registry; only TCP is ever used. The split between the two connections is the single most useful thing to know about this port. A session opens on 21 and everything you type travels there in readable ASCII — `USER`, `PASS`, `LIST`, `RETR` — along with the server's numeric replies, but not one byte of file content does. Each transfer opens a second TCP connection, and which side dials it decides whether your firewall lets it through. In active mode the client sends `PORT`, or `EPRT` from RFC 2428, and the server connects back to the client, which nearly every NAT and client-side firewall now blocks. In passive mode the client sends `PASV` and the server answers `227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)`, where the last two numbers are a port written as `p1 * 256 + p2`, or answers `229 Entering Extended Passive Mode (|||port|)`; the client then dials that. Passive is what everything defaults to today, and it is why an FTP server needs a configured range of data ports opened alongside 21 rather than 21 on its own. Then there is the naming trap that brings most people here: FTPS and SFTP are not two spellings of the same thing. FTPS is FTP with TLS added by RFC 4217 — the client sends `AUTH TLS` on this same port 21 and the session continues encrypted — and IANA separately assigned 990 to `ftps` for the older implicit variant that is encrypted from the first byte with no `AUTH` command at all. SFTP is not FTP in any form: it is a subsystem of SSH on port 22, it shares no commands, no reply codes and no second data connection with FTP, and it needs nothing opened but 22.

Should port 21 face the internet?

Do not put plaintext FTP on the internet. The password crosses the wire in the clear on port 21, exactly as telnet's does, and a public listener is found by internet-wide scanners within hours and then tried against anonymous access and vendor defaults. Two habits make FTP servers leak more than most: anonymous read access that was switched on for one file and never switched off, and a document root that was never chrooted per user, so an authenticated account can walk out of its own directory. If all you need is to hand files to someone, HTTPS on 443 does that with far less surface. If you need an interactive file session, SFTP over SSH on 22 needs one port, verifies the server's host key and encrypts commands and content together. When FTP genuinely has to stay — an appliance, a lab instrument, a partner who will not change — require explicit FTPS with `AUTH TLS`, and understand that securing the control connection does not secure the transfer: the data connection is encrypted only when the client also requests `PROT P`, so a session can authenticate under TLS and still ship the file in clear text. Pin the passive port range in the server configuration so the firewall rule is a narrow window instead of the whole high range, restrict the service by source address, and check what your router actually forwards rather than trusting NAT to hide it.

Service
FTP
Transport
TCP
Registry
IANA assigned
Category
File transfer

Tools on this site

All of these run in your browser — nothing is uploaded.

Related ports

Ports people usually end up checking in the same session as 21.

Frequently asked questions

Why does the command show nothing when the port is clearly in use?

Almost always permissions. lsof and ss list the socket but hide the owning process when it belongs to another user, so a server started by a system account, by a container runtime or by launchd shows up as an anonymous listener until you re-run the command with sudo. On Windows the opposite happens: netstat shows nothing at all, yet a bind still fails, which means the port sits inside a range that Hyper-V, WSL2 or Docker Desktop reserved at boot.

Is it safe to kill whatever is holding the port?

Look at what it is first. An orphaned dev server is safe to kill; a database with a write in flight is not, and neither is a system service that something else depends on. If the owner is a container, stop the container instead — killing the process the host sees only makes the runtime restart it. When the process is something you need, moving your own service to another port is the faster fix.

Why can I reach the port locally but not from another machine?

The listener bound to 127.0.0.1 rather than 0.0.0.0. The probes on every page print the bound address next to the process for exactly this reason: a loopback bind is reachable from the machine itself and from nowhere else, no matter how the firewall is configured. Many frameworks made that the default deliberately, so it is usually a flag rather than a bug. If the address is already 0.0.0.0 and it still fails, the next suspect is a host firewall or a cloud security group.

Does moving a service to an unusual port make it safer?

Barely. Internet-wide scanners sweep the whole port range continuously, so an unusual number buys hours, not safety, and it costs you every colleague who now has to remember it. It does cut the noise in your logs from opportunistic scans of the default port, which is a real if modest benefit. Authentication, a firewall that restricts source addresses, and not exposing the service at all are the measures that actually change the outcome.

Still stuck on port 21? browse every port in the reference — or go back to the failure message you actually got, above.