FTP
The File Transfer Protocol moves files over two TCP connections: one for commands, one per transfer. Clear text by default, so usernames, passwords and files are visible in any capture.
- OSI layer
- 7 Application
- Carried in
- TCP
- Ports
- 21/tcp (control), 20/tcp (active data), 990/tcp (implicit FTPS), dynamic (passive data)
- Wireshark filter
ftp || ftp-data- Encrypted
- no
Packet structure
Like SMTP, FTP is line-based text on the control connection (port 21). Files and directory listings travel on a separate data connection.
S: 220 ProFTPD Server ready
C: USER alice
S: 331 Password required for alice
C: PASS hunter2
S: 230 User alice logged in
C: TYPE I
S: 200 Type set to I
C: PASV
S: 227 Entering Passive Mode (192,0,2,10,195,80)
... client opens a data connection to 192.0.2.10:50000 ...
C: RETR report.pdf
S: 150 Opening BINARY mode data connection
S: 226 Transfer complete
C: QUIT
S: 221 Goodbye
The passive reply encodes address and port as six numbers: h1,h2,h3,h4,p1,p2, port = p1 × 256 + p2 (195 × 256 + 80 = 50000).
| Command | Purpose |
|---|---|
USER / PASS | Log in (in clear text) |
PASV / EPSV | Passive mode: the server opens a port for the data connection |
PORT / EPRT | Active mode: the client tells the server where to connect |
LIST, NLST, MLSD | Directory listing (over the data connection) |
RETR / STOR | Download / upload |
CWD, PWD, MKD, DELE | Change dir, show dir, make dir, delete |
TYPE A / TYPE I | ASCII / binary mode |
AUTH TLS | Upgrade to FTPS (explicit) |
SITE | Server-specific commands (old exploits, e.g. SITE EXEC) |
| Reply | Meaning |
|---|---|
| 1xx | Preliminary (150 opening data connection) |
| 2xx | Done (220 ready, 226 transfer complete, 227 passive mode, 230 logged in) |
| 3xx | Need more (331 password required) |
| 4xx | Temporary failure (421 service not available, 425 can’t open data connection) |
| 5xx | Permanent failure (530 not logged in, 550 file unavailable or no permission) |
How it works
| Mode | Data connection | Firewall issue |
|---|---|---|
| Active | Server connects from port 20 to the port the client sent with PORT | Client firewalls and NAT block it |
| Passive | Client connects to the port the server sent in the 227 reply | Server needs a range of open ports |
Firewalls with an FTP helper read the control connection to open the right data port, which does not work once the control channel is encrypted (FTPS).
In Wireshark
| Filter | Shows |
|---|---|
ftp | Control connection (commands and replies) |
ftp-data | Data connections (files, listings) |
ftp.request.command == "PASS" | Passwords in clear text |
ftp.request.command == "USER" | User names (look for anonymous) |
ftp.response.code == 530 | Failed logins (brute force if repeated) |
ftp.request.command == "STOR" | Uploads |
ftp.request.command == "PORT" | Active mode (and bounce attempts to third-party IPs) |
File › Export Objects › FTP-DATA saves transferred files. Follow › TCP Stream on the control connection shows the whole session.
What normal looks like: rare today. Mostly legacy systems, printers and scanners, some industrial devices. Any FTP to the internet deserves a look.
Security notes
- Clear-text credentials and data: anyone on the path reads
USER/PASSand every file. Use SFTP (over SSH) or FTPS. - Anonymous login:
anonymouswith any password; often world-readable or even writable shares. Check withnmap --script ftp-anon. - Brute force: many 530 replies from one source.
- FTP bounce:
PORTwith a third-party address makes the server connect elsewhere (old port-scan and firewall-bypass trick,nmap -b). Modern servers refuse it. - Exfiltration:
STORto an external server is a simple and still used way to move data out. - Vulnerable servers: old vsftpd (2.3.4 backdoor), ProFTPD
mod_copy, and many embedded FTP servers.
Versions and related
- FTPS: FTP with TLS, explicit (
AUTH TLSon 21) or implicit (990). - SFTP: a completely different protocol that runs inside SSH; no relation to FTP except the purpose.
- TFTP (69/udp): trivial FTP without authentication, used for PXE boot and network device configs.