FTP

Also known as: File Transfer Protocol

On this page 7

FTP, the File Transfer Protocol, is a client-server application-layer protocol that transfers files between hosts over TCP, using one connection for commands and a separate connection for data. Among Internet protocols it is one of the oldest still in service: its current form is defined in RFC 959 from 1985, and its design predates the web, TLS and most of the security assumptions that later Internet protocols take for granted.

FTP remains relevant because it is simple, universally supported by servers, embedded devices and legacy business systems, and efficient for bulk transfer. Its weaknesses are equally well known: credentials and data travel in plain text unless the session is wrapped in TLS, and its two-connection model complicates firewalls and NAT.

How FTP separates control and data

FTP works by opening a control connection to the server, normally on TCP port 21, and then opening a new data connection for each file transfer or directory listing. The control channel carries short text commands and three-digit replies for the whole session, while the data channel exists only for the duration of one transfer and closes when it ends.

Commands are plain ASCII lines such as USER, PASS, CWD, LIST, RETR and STOR. Replies begin with a numeric code whose first digit signals the outcome, which makes the protocol easy to script and to debug with a raw terminal session. This out-of-band control design lets a client abort a transfer or query status while data is still flowing.

The following table summarizes the most common commands and what each one does in a typical session.

CommandPurposeTypical reply on success
USER / PASSSend user name and password331, then 230 logged in
CWD / PWDChange or print working directory250 or 257
LIST / NLSTReturn directory listing over data channel150, then 226
RETRDownload a file from the server150, then 226
STORUpload a file to the server150, then 226
PASV / EPSVAsk the server to open a data port227 or 229
TYPESelect ASCII or binary (image) mode200
QUITEnd the session221
Core FTP commands and their purpose

Active mode, passive mode and firewalls

The direction in which the data connection is opened defines the FTP transfer mode. In active mode, the client announces an address and port with the PORT command and the server connects back to the client from port 20. In passive mode, the client sends PASV or EPSV, the server replies with a port it is listening on, and the client opens the data connection itself.

Active mode breaks easily behind client-side NAT and stateful firewalls, because an inbound connection to the client is unexpected. Passive mode moves the problem to the server, which must allow a defined range of high ports. Many firewalls include an FTP application-layer gateway that reads the control channel and opens the matching data port, but that inspection fails once the control channel is encrypted.

ModeWho opens the data connectionFirewall impactTypical use
Active (PORT)Server connects to clientBlocked by most client NATLegacy LAN transfers
Passive (PASV)Client connects to serverServer must open a port rangeDefault for modern clients
Extended passive (EPSV)Client connects to serverPort only, works with IPv6IPv6 and NAT-heavy networks
Extended active (EPRT)Server connects to clientSame issues as active modeRare, IPv6 active transfers
Comparison of FTP connection modes

In practice, administrators configure a fixed passive port range, for example 50000 to 51000, and publish the external IP address the server must advertise. A wrong advertised address is the most frequent cause of clients that log in successfully but hang on the first directory listing.

Transfer types, structures and resume

FTP distinguishes ASCII mode from binary (image) mode. ASCII mode converts line endings between operating systems, which suits plain text files; binary mode copies bytes unchanged and is required for archives, images and executables. Transferring a binary file in ASCII mode silently corrupts the file, a classic mistake that modern clients reduce through automatic type detection.

The REST command allows a client to resume an interrupted transfer from a byte offset, which matters on slow or unstable links. Extensions defined in later RFCs add SIZE, MDTM for modification time and MLSD for machine-readable directory listings, replacing the inconsistent output of LIST that clients once had to parse heuristically.

FTP compared with FTPS, SFTP and HTTPS

FTP is often confused with secure alternatives that solve the same problem differently. FTPS is FTP secured with TLS, either explicitly through the AUTH TLS command on port 21 or implicitly on port 990. SFTP is not FTP at all but a subsystem of SSH running over a single connection on port 22, and HTTPS can also carry uploads and downloads through ordinary web requests.

The table compares the protocols on the properties that usually drive a decision.

ProtocolEncryptionConnections and portsAuthentication
FTPNoneControl 21 plus dynamic data portsPassword in plain text
FTPSTLS on both channels21 or 990 plus data portsPassword, optional client certificate
SFTPSSH transportSingle connection on 22Password or SSH keys
HTTPSTLSSingle connection on 443Tokens, cookies, certificates
File transfer protocols compared

For new systems, SFTP or HTTPS-based transfer is generally preferred because a single encrypted connection passes firewalls cleanly. FTPS remains common where existing FTP workflows must be secured without replacing client software, for example in banking file exchange and retail supply chains.

Security limitations and common mistakes

Plain FTP offers no confidentiality and no integrity protection. Anyone on the network path can capture the user name, password and file contents, and an attacker in the middle can alter data without detection. Major browsers removed FTP support around 2021, which reflects how far the protocol has fallen from general use.

Additional risks come from configuration rather than the protocol itself. The table lists frequent problems, their causes and the usual remedies.

Symptom or riskCauseFix
Login works, listing hangsPassive ports blocked or wrong advertised IPOpen port range, set external address
Corrupted archivesTransfer in ASCII modeForce binary mode
Stolen credentialsPlain-text authenticationUse FTPS or SFTP
Server used as relayFXP or PORT bounce allowedDisable bounce and site-to-site transfers
Exposed public filesAnonymous FTP enabled by defaultDisable anonymous access or isolate it
Typical FTP problems and fixes
  • Never reuse FTP passwords for other systems, since they may already be exposed.
  • Restrict users to their home directory (chroot) to limit damage from a compromised account.
  • Log all sessions and review failed logins, because FTP servers attract automated password guessing.

Explained without jargon

FTP is an old and simple way to copy files between computers across a network. One line is used to talk, giving instructions such as which folder to open or which file to send. A second line opens briefly to carry the file itself.

The catch is that plain FTP sends everything openly, like writing a password on a postcard. For anything private, use a secure version such as FTPS or SFTP, which keep the conversation and the files hidden from anyone listening on the way.

A typical use case

A regional manufacturer runs older machine controllers on its factory floor that can only export production logs over FTP. The IT team sets up an internal FTP server on an isolated network segment, gives each controller its own account restricted to one directory, and configures a passive port range of 40000 to 40100 on the server firewall.

Every night, the controllers upload about 2 GB of log files in binary mode. A separate job then moves the files over SFTP to the central data platform, so plain FTP never crosses the corporate network or the Internet. The result is that legacy equipment keeps working without replacement, while credentials and production data stay protected outside the isolated segment.