Application Layer · Computer Networks

File Transfer Protocol (FTP)

Watch lectures
SVGVector Architecture Diagram (SVG)
COMPUTER NETWORKS · Module 5 · Application Layer★ High PriorityIT Sem 6 · Code 100602File Transfer Protocol (FTP)MNEMONICFTP = TWO connections: Control on 21 (commands), Data on 20 (files).Active: server connects back. Passive: client connects out.Core BreakdownOverviewFTP (RFC 959) moves files between hosts over TCP, with login and directory commands.Client-server; reliable TCP, so no file data is lost or reordered.Two ChannelsControl connection: TCP 21, stays open for the whole session, carries commands and replies.Data connection: opened for each file or listing, then closed (out-of-band control).Active ModeClient opens control on 21 and sends PORT with its own IP and port.The SERVER then opens the data link from port 20 to the client: NAT / firewalls often block it.Passive ModeClient sends PASV; the server replies with an IP and a random high port.The CLIENT opens the data link outward, so it works behind firewalls and NAT.CommandsUSER, PASS (login) · LIST, CWD, PWD (browse) · RETR (download) · STOR (upload) · QUIT.Replies are 3-digit codes: 220 ready, 230 logged in, 226 transfer done, 530 not logged in.Data TypesFile types: ASCII (text, line-end conversion) or Image / binary (no conversion).Transmission modes: stream (default), block, compressed.AnonymousPublic servers allow user "anonymous" with an e-mail address as the password.Normal accounts send USER / PASS in clear text: the protocol has no encryption.Secure FTPFTPS = FTP over SSL / TLS (ports 990 implicit, or 21 with AUTH TLS).SFTP is a different protocol: file transfer inside SSH on TCP 22.Diagram: FTP ConnectionsFTP Clientuser PI + DTPFTP Serverserver PI + DTPControl: TCP 21Data: TCP 20 (active)Active modeClient sends PORT; SERVER opens data linkfrom port 20 to the client. Firewalls block it.Passive modeClient sends PASV; server gives a random port;CLIENT opens the data link. Firewall-friendly.USER / PASSLIST / CWDRETR (download)STOR (upload)Replies: 220 ready · 230 login OK · 331 need password226 transfer done · 425 cannot open data link · 530 not logged inModes: stream · block · compressed Types: ASCII / binaryOut-of-band: control and data use separate connections⚠️ Exam Traps & Viva Favorites① Which ports are used?Control = 21, Data = 20 (active mode).Passive mode uses a random server portfor data. Two connections, not one.② Active vs Passive?Active: server opens the data link.Passive: client opens it (PASV), so itpasses firewalls and NAT easily.③ FTPS or SFTP?FTPS = FTP + SSL/TLS. SFTP = a separateprotocol over SSH on port 22. Plain FTPsends passwords in clear text.Tip: 21 cmd · 20 data · PASV=clientMaster Revision Table(learn it row by row!)ItemPortOpened byPurposePitfallControl linkTCP 21ClientCommands and repliesStays open all sessionData link (active)TCP 20ServerFile and listing dataBlocked by firewallsData link (passive)RandomClientFile and listing dataServer needs port rangeRETR / STORn/aClient commandDownload / upload a fileDo not mix them upFTPS990 / 21ClientFTP secured with TLSNot the same as SFTPSFTPTCP 22ClientFile transfer over SSHDifferent protocolQUICK FACTSPorts: control 21 · data 20 (active) · FTPS implicit 990 · SFTP 22Commands: USER PASS LIST CWD RETR STOR QUIT · Replies: 220 230 226 530Out-of-band control: commands and data use separate TCP connectionsVERIFIED★ Golden rule: FTP = control 21 + data 20; passive = client opens data.

File Transfer Protocol (FTP)


1. Overview and Design Philosophy

The File Transfer Protocol (FTP) (RFC 959) is an Application Layer protocol designed to transfer files reliably, securely, and efficiently between two computers across a TCP/IP network.

Unlike most client-server protocols (which use a single communication channel), FTP is famous for its Dual-Connection Architecture (Out-of-Band Control): it uses two completely separate parallel TCP connections for a single user session:

MermaidDiagram
Rendering diagram…

2. The Two Connections: Control vs. Data

SVGVector Architecture Diagram (SVG)
FEATURE CONTROL CONNECTION DATA CONNECTION Default Server Port TCP Port 21 TCP Port 20 (Active) Lifetime Entire session length Ephemeral (Per file) Data Format 7-bit ASCII commands Raw bytes / binary Purpose Authentication & Cmds File content & listings

Why Use Two Separate Connections?

  1. Out-of-Band Signaling: Control commands travel on a clean, dedicated channel uninterrupted by massive multi-gigabyte file payloads.
  2. Interactive Abort: If a user initiates a 10 GB file download and wants to cancel it mid-transfer, they can immediately send an ABOR command across the Control Connection. In single-connection protocols (like HTTP/1.0), the client must download or terminate the entire socket!

3. Active Mode vs. Passive Mode (The Firewall Problem)

FTP operates in two distinct operational modes, differing in which entity initiates the Data Connection:

MermaidDiagram
Rendering diagram…

1. Active Mode (Default):

  • The client tells the server its IP address and an arbitrary local port (MM) using the PORT command.
  • The server initiates the data connection from its own TCP Port 20 back to the client's port MM.
  • Problem: Modern client NAT routers and personal firewalls block unsolicited inbound connection attempts from the outside Internet!

2. Passive Mode (PASV):

  • The client sends a PASV command across the control connection.
  • The server opens an unprivileged ephemeral port (e.g., 3200032000) and returns this port number to the client.
  • The client initiates the data connection outbound to the server's ephemeral port.
  • Advantage: Because both the Control and Data connections originate outbound from the client, client firewalls allow the connections without interference.

4. Common FTP Commands and Status Codes

Standard Commands:

  • USER <username>: Submits user identity.
  • PASS <password>: Submits authentication password.
  • LIST: Requests a list of files in the current remote directory.
  • RETR <filename>: Retrieve (download) a file from server to client.
  • STOR <filename>: Store (upload) a file from client to server.
  • QUIT: Terminates the session.

3-Digit Status Response Codes:

  • 1xx: Positive Preliminary reply (e.g., 150 Opening BINARY mode data connection).
  • 2xx: Positive Completion reply (e.g., 220 Service ready, 230 User logged in, 226 Transfer complete).
  • 3xx: Positive Intermediate reply (e.g., 331 Password required).
  • 4xx: Transient Negative reply (e.g., 425 Can't open data connection).
  • 5xx: Permanent Negative error (e.g., 530 Login incorrect, 550 File not found).

5. Security Limitations and Modern Replacements

Standard FTP transmits all credentials (usernames and passwords) and file contents in unencrypted cleartext.

  • FTPS (FTP Secure): Adds TLS encryption to standard FTP (RFC 4217).
  • SFTP (SSH File Transfer Protocol): A completely different, modern protocol running over SSH (TCP Port 22) that provides encrypted file transfers over a single multiplexed connection.

Frequently Asked Questions

QWhy does FTP use two separate TCP connections?

It separates control commands (PORT 21) from data transfer (PORT 20 / PASV), allowing control commands (such as directory changes or transfer aborts) to be processed immediately without being blocked by large transferring files.

QWhat is the difference between Active FTP and Passive FTP?

In Active FTP, the server initiates the data connection back to the client from Port 20 (often blocked by client firewalls). In Passive FTP, the client initiates both the control and data connections to the server, bypassing client firewall restrictions.

QWhat port does the FTP control connection use?

TCP Port 21.

QHow do FTPS and SFTP differ?

FTPS is standard FTP with TLS encryption added (still two connections). SFTP is a different protocol that runs over SSH on TCP port 22 and multiplexes everything over a single encrypted connection.

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.

← All Computer Networks modules