Home CCNA File Transfer Protocol (FTP): How It Works and How to Secure It
CCNA

File Transfer Protocol (FTP): How It Works and How to Secure It

Diagram Showing Ftp'S Command Channel On Port 21 And Data Channel On Port 20 Between A Client And Server

File Transfer Protocol is one of the oldest application layer protocols still in active use today. Its original specification, RFC 114, dates back to 1971 — decades before the modern web existed. It’s still worth understanding in depth, both because it shows up regularly in CCNA and CCNP material and because plenty of real infrastructure still relies on it, for better or worse.

This guide covers how FTP actually works, the real difference between active and passive mode, what genuinely works (and doesn’t) for securing it on Windows and Linux, and practical troubleshooting steps.

How File Transfer Protocol (FTP) Works

FTP is a client-server application layer protocol built for transferring files over TCP/IP. A client application connects to a server daemon — commonly vsftpd or ProFTPD on Linux — using two separate channels:

  • Command channel (port 21): carries control messages between client and server — client commands like USER and PASS, and server status-code replies.
  • Data channel (port 20): dedicated to the actual file transfer itself, separate from the control conversation.

The client opens the command connection first. Once that’s negotiated successfully, a separate data connection is established for each individual file transfer. This two-channel design is unusual among common application layer protocols — most, like HTTP, handle everything over a single connection — and it’s exactly what makes FTP more complicated to work with through firewalls and NAT.

You can monitor both channels’ activity directly:

Windows:

netstat -a

Linux:

ss -l

Depending on the permissions granted, an FTP client can download, upload, delete, rename, move, and copy files on the server. Most servers require authentication, though some allow anonymous access with deliberately restricted privileges — a useful real-world example of access control principles in practice.

Sequence Diagram Showing Ftp Command Channel Negotiation Followed By Data Channel File Transfer
The Order Of Operations From Command Channel Login To Data Transfer

Active Mode vs. Passive Mode

FTP’s two-channel design creates a genuine complication: who initiates the data connection, and in which direction?

Active mode: the client opens the command channel to the server’s port 21 as usual. For the data transfer, the server then initiates a new connection back to the client, from the server’s port 20 to a port the client specified. This means the client-side firewall has to allow an unsolicited inbound connection — something firewalls are specifically designed to block by default, which makes active mode unreliable on any network with a properly configured firewall or behind NAT.

Passive mode: the server instead opens a dynamic port, somewhere in the ephemeral range (commonly 1024–65535, though many administrators restrict this to a narrower range specifically to simplify firewall configuration), and tells the client which port to use over the command channel. The client then initiates the data connection itself, in the same direction as the original command connection. This makes passive mode dramatically more compatible with modern firewalls and NAT, which is why it’s the default choice in nearly every FTP client today.

A note on Windows’ built-in FTP client: this is worth being precise about, because it trips people up. Windows’ native ftp.exe command-line client does not reliably support passive mode, on any current version of Windows — there’s no -p switch, and even the “quote pasv” workaround only tells the server to switch to passive mode while the client itself remains stuck in active mode, which typically causes the transfer to hang. If you need passive mode on Windows, use a dedicated client like FileZilla or WinSCP instead of the built-in command-line tool.

On Linux, you can test a passive-style connection manually with:

nc -l 2121
Comparison Diagram Showing Active Mode Data Connections Blocked By A Firewall Versus Passive Mode Connections Succeeding
Why Passive Mode Works Reliably Behind Firewalls And Active Mode Often Doesn’T

Practical Example: Connecting to an FTP Server

On Linux, open a terminal and connect directly:

ftp ftp.example.com

Log in with a username and password, or anonymous for public servers that allow it. Once connected, use dir or ls to list files, get filename to download, and put filename to upload.

On Windows, the built-in client can run from a script file for repeatable, non-interactive transfers. Create a text file (for example, script.txt) containing:

open ftp.example.com
user username password
dir

Then run it from the Command Prompt:

ftp -s:script.txt

Confirm the connection actually worked with netstat -a on either platform, checking that port 21 shows an active connection.

Securing FTP: What Actually Works

Plain FTP transmits everything — including your username and password — in unencrypted plaintext. Anyone able to observe the traffic, on a shared network or anywhere along the route, can read it directly. This isn’t a minor caveat; it’s the single biggest reason FTP has fallen out of favor for anything sensitive.

There are two genuinely different ways to secure file transfer, and they’re often confused with each other:

  • FTPS (FTP over TLS/SSL): the original FTP protocol, with an added TLS encryption layer on top. It still uses the same command/data channel structure as plain FTP.
  • SFTP (SSH File Transfer Protocol): a completely different protocol that transfers files over an SSH connection. Despite the similar name, SFTP shares no code or protocol lineage with FTP — it’s built on SSH from the ground up.

Both are secure, well-supported alternatives to plain FTP. Which one to use often comes down to what your existing infrastructure already supports — SFTP is generally simpler to firewall, since it only needs a single port (22, the same as SSH).

Setting up FTPS on Linux with vsftpd:

sudo apt install vsftpd

Edit /etc/vsftpd.conf to enable TLS:

ssl_enable=YES
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.key

Restart the service to apply the changes:

sudo systemctl restart vsftpd

Setting up FTPS or SFTP on Windows: since the built-in ftp.exe client supports neither encryption method, use FileZilla Server for FTPS (enable TLS in its settings and configure a certificate) or an SSH server for SFTP. On the client side, FileZilla Client or WinSCP both handle FTPS and SFTP correctly.

Testing a secure connection:

sftp user@host

For FTPS, connect using a client that actually supports it — FileZilla Client is the simplest cross-platform option — rather than the plain Windows or Linux command-line ftp tool, neither of which handles TLS negotiation.

Three-Column Comparison Chart Of Ftp, Ftps, And Sftp Showing Encryption Status And Ports Used
Three Protocols With Similar Names And Very Different Security Postures

Troubleshooting Tips

Connection fails entirely: start with basic reachability.

ping ftp.example.com

If that succeeds but the FTP connection still fails, trace the path to rule out routing problems:

tracert ftp.example.com

On Linux, use traceroute ftp.example.com instead.

Data transfer stalls after connecting: this is the classic active-mode-behind-a-firewall symptom. Confirm both port 21 (command) and, if using active mode, port 20 (data) are actually open and responding:

netstat -a

On Linux:

ss -l

Switching to passive mode, or moving to a client that properly supports it, resolves the majority of stalled-transfer cases.

Firewall blocking legitimate FTP traffic: on Linux, allow the command port explicitly if needed:

sudo ufw allow 21/tcp

Remember that passive mode also requires the server’s configured passive port range to be open, not just port 21 — a common oversight when troubleshooting FTP through a firewall.

Understanding FTP Reply Codes

Every FTP server response begins with a three-digit status code, and recognizing the pattern makes troubleshooting significantly faster:

Code RangeMeaningExample
1xxPositive preliminary reply — action started, another reply will follow150 File status okay, opening data connection
2xxPositive completion reply — action finished successfully226 Transfer complete
3xxPositive intermediate reply — more information needed to complete the request331 Username okay, password required
4xxTransient negative reply — the request failed, but may succeed if retried425 Can’t open data connection
5xxPermanent negative reply — the request failed and won’t succeed without a change530 Not logged in

A 227 reply specifically indicates the server has entered passive mode and is telling the client which port to connect to for the data transfer — this is the exact reply that Windows’ native ftp.exe can receive and acknowledge, but still fails to act on correctly, which is the root of its passive-mode limitation described above.

If a session hangs immediately after a 150 reply, the data channel itself is the problem — usually a firewall blocking either the server’s port 20 (active mode) or the dynamic passive port range, even though the command channel on port 21 is working fine.

FTP vs. Its Modern Alternatives

FactorFTPFTPSSFTP
EncryptionNoneTLS/SSLSSH
Ports required21 (control) + 20 or dynamic (data)Same as FTP, plus TLS negotiation22 only
Firewall complexityHigh, especially in active modeHigh — same channel structure as FTPLow — single port
Native Windows client supportYes (unencrypted only)NoNo (requires third-party client or PowerShell/OpenSSH)
Recommended for sensitive dataNoYesYes

Why FTP Is Still Around

Given its security limitations, it’s fair to ask why FTP hasn’t simply disappeared. A few reasons keep it in active use: a huge amount of legacy infrastructure, embedded devices, and internal tooling was built around it decades ago and hasn’t been replaced; some internal, network-isolated environments accept the plaintext risk because the traffic never leaves a trusted network; and FTP’s command set is simple enough that it remains a useful teaching tool for understanding client-server file transfer and the active/passive connection problem more broadly. None of that makes plain FTP a good choice for anything crossing an untrusted network today — but it explains why CCNA and CCNP material still cover it in depth.

FAQs

What is the purpose of File Transfer Protocol?

FTP is a client-server application layer protocol, dating back to a 1971 specification, built specifically for transferring files between systems over TCP/IP. It uses a command channel on port 21 and a data channel on port 20 to handle authentication, file listing, and the actual upload or download of files.

How do active and passive modes differ in File Transfer Protocol (FTP)?

In active mode, the server initiates the data connection back to the client after the command channel is established, which often fails behind a firewall since it requires an unsolicited inbound connection. In passive mode, the client initiates the data connection instead, using a dynamic port the server provides — this is far more firewall- and NAT-friendly and is the default in nearly every modern FTP client.

What are the security limitations of FTP?

Plain FTP transmits usernames, passwords, and file contents entirely in cleartext, meaning anyone who can observe the network traffic can read everything, including your login credentials. This is a serious enough limitation that FTP should not be used for anything sensitive without upgrading to FTPS or SFTP.

What’s the actual difference between FTPS and SFTP?

FTPS is the original FTP protocol with TLS encryption added on top, keeping the same two-channel command/data structure. SFTP is a completely different protocol that transfers files over an SSH connection, sharing no code or protocol lineage with FTP despite the similar name — and it’s generally easier to firewall since it only needs a single port.

Does Windows’ built-in FTP client support passive mode or encryption?

No, on both counts. Windows’ native ftp.exe does not reliably support passive mode on any current Windows version, and it has no support for FTPS or SFTP encryption at all. For either passive mode or secure transfers on Windows, use a dedicated client like FileZilla or WinSCP instead.

How can users access an FTP server without logging in?

Some FTP servers allow anonymous access, letting users download or browse public content using “anonymous” as the username and typically an email address as the password. This access is usually restricted to read-only, specific directories, and should always be configured deliberately by the server administrator rather than left as an unintentional default.

Avatar Of Mujtaba Khattak
Mujtaba Khattak

Editor & Founder

Mujtaba Khattak is a network solutions architect specializing in SD-WAN, cloud infrastructure, and network optimization. He holds a BS in Artificial Intelligence from SZABIST, an MBA from Virtual University (VU), and Cisco certifications (CCNA and CCNP). As the founder of NetworkUstad.com, Mujtaba authors technical guides and tutorials on networking, cybersecurity, and AI applications, with over 160 published posts. He bridges AI innovation with practical networking solutions to empower IT professionals and enthusiasts.

Related Articles