π€ What is FTP? (Basic Idea)
Sometimes we need to:
Upload files to a server β¬οΈ
Download files from a server β¬οΈ
Manage files remotely π
π This is done using FTP.
π§ Simple Definition
π FTP (File Transfer Protocol) is an application-layer protocol used to transfer files between a client and a server over a network.
π§ Why FTP is Needed
FTP is used when:
Files are large
Regular email attachment is not suitable
Files must be stored on a remote server
π Examples:
Website file upload
Software distribution
Backup storage
π§ Real-Life Analogy
π¦ Bank Locker Example
You go to the bank (server)
You authenticate (login)
You deposit or withdraw files (upload/download)
π FTP works the same way.
π§ Where Does FTP Belong in OSI Model?

FTP is an Application Layer protocol
Uses TCP for reliable transfer
π Ports Used by FTP
FTP uses two different connections:
Connection | Port | Purpose |
|---|---|---|
Control Connection | 21 | Commands & responses |
Data Connection | 20 (or dynamic) | Actual file transfer |
π This makes FTP different from most protocols.
π§© Two Connections in FTP (Key Concept)
πΉ Control Connection
Established first
Remains open throughout session
Used for:
Login
Commands
Responses
πΉ Data Connection
Created only when needed
Used for:
Upload
Download
Directory listing
π Closed after transfer completes.
π FTP Authentication
FTP supports:
π€ Username
π Password
π Two login modes:
π Anonymous FTP
Username:
anonymousPassword: email (optional)
π Used for public downloads.
π Authenticated FTP
Requires valid username/password
Used for secure access
π FTP Working (Step-by-Step)

1οΈβ£ Client connects to server on port 21
2οΈβ£ Server asks for username/password
3οΈβ£ Client authenticated
4οΈβ£ Control connection stays open
5οΈβ£ Data connection opened when file transfer requested
6οΈβ£ File transferred
7οΈβ£ Data connection closed
8οΈβ£ Session ends
π Modes of FTP: Active vs Passive
β‘ 1. Active FTP
π§ How Active FTP Works
1οΈβ£ Client opens control connection to server
2οΈβ£ Client tells server its port
3οΈβ£ Server opens data connection from port 20 to client
π Server initiates data connection.
β Problems
Firewalls block incoming connections
Client security issues
π§² 2. Passive FTP
π§ How Passive FTP Works
1οΈβ£ Client opens control connection
2οΈβ£ Client requests passive mode
3οΈβ£ Server provides a port number
4οΈβ£ Client opens data connection to server
π Client initiates both connections βοΈ
β Advantages
Firewall friendly
Most commonly used today
βοΈ Active vs Passive FTP
Feature | Active FTP | Passive FTP |
|---|---|---|
Data connection initiated by | Server | Client |
Firewall friendly | β No | β Yes |
Security | Lower | Higher |
Usage | Rare today | Common |
π Common FTP Commands
Command | Purpose |
|---|---|
USER | Send username |
PASS | Send password |
LIST | List directory |
RETR | Download file |
STOR | Upload file |
QUIT | End session |
β Security Issues with FTP
FTP has major security problems:
β Username sent in plain text
β Password sent in plain text
β Data not encrypted
π Anyone can sniff data π¨
π Secure Alternatives to FTP
Protocol | Description |
|---|---|
SFTP | FTP over SSH |
FTPS | FTP over SSL/TLS |
SCP | Secure copy |
π Used in modern systems.
π§ FTP vs HTTP (Quick Comparison)
Feature | FTP | HTTP |
|---|---|---|
Purpose | File transfer | Web data |
Connections | Two | One |
State | Stateful | Stateless |
Security | Low | High (HTTPS) |
π§ Memory Tricks
FTP = File Transfer
21 = Control
20 = Data
Passive = Client starts everything
β One-Line Summary
πΉ FTP is an application-layer protocol that transfers files using separate control and data connections over TCP.