File Transfer Protocol (FTP)
File Transfer Protocol (FTP)
File Transfer Protocol (FTP) is the standard application-layer protocol in the TCP/IP suite used for transferring files between two computers over a network. It provides a reliable and efficient method for copying files from one host to another using the services of TCP. FTP is especially suitable for transferring large files and files in different formats, making it more efficient than HTTP for file transfer.
Need for FTP
Simple file transfer between two computers is complicated because:
- Different operating systems use different file naming conventions.
- Different systems represent data differently (ASCII, EBCDIC, Binary).
- Directory structures vary from one operating system to another.
FTP provides a standard method to overcome these differences and enables reliable file transfer between heterogeneous systems.
FTP Architecture
FTP follows the client-server architecture.
The FTP client consists of:
- User Interface
- Client Control Process
- Client Data Transfer Process
The FTP server consists of:
- Server Control Process
- Server Data Transfer Process
Communication takes place using two separate TCP connections:
- Control Connection
- Data Connection
Why FTP Uses Two Connections
FTP separates:
- Commands from
- Actual file transfer
This separation makes FTP more efficient.
- The control connection carries only commands and responses.
- The data connection carries the actual file contents.
FTP Connections
1. Control Connection
The control connection is responsible for exchanging commands and responses.
Characteristics
- Uses TCP Port 21
- Established once when the FTP session starts
- Remains open throughout the entire FTP session
- Closed only when the user logs out
Examples of information exchanged:
- Username
- Password
- File names
- Directory names
- File type
- Transfer mode
2. Data Connection
The data connection is responsible for transferring actual data.
Characteristics
- Uses TCP Port 20 at the server
- Opened whenever a file transfer is required
- Closed immediately after the transfer completes
- Can be opened and closed multiple times during one FTP session
Data transferred includes:
- Files
- Directory listings
Lifetime of FTP Connections
| Control Connection | Data Connection |
|---|---|
| Open throughout FTP session | Open only during file transfer |
| Uses Port 21 | Uses Port 20 |
| Transfers commands | Transfers actual data |
FTP Commands
FTP communication is performed using commands sent from the client to the server.
Some common FTP commands are:
| Command | Purpose |
|---|---|
| USER | Send user name |
| PASS | Send password |
| LIST | Display directory contents |
| PWD | Display current directory |
| CWD | Change directory |
| RETR | Retrieve (download) a file |
| STOR | Store (upload) a file |
| DELE | Delete a file |
| MKD | Create a directory |
| RMD | Remove a directory |
| RNFR | Rename old file |
| RNTO | Rename new file |
| TYPE | Select file type |
| MODE | Select transmission mode |
| QUIT | End FTP session |
FTP Responses
Each command generates a response from the server.
A response consists of:
- Three-digit status code
- Text explanation
Common FTP Response Codes
| Code | Meaning |
|---|---|
| 200 | Command successful |
| 220 | Service ready |
| 221 | Service closing |
| 226 | Data transfer completed |
| 230 | User logged in successfully |
| 331 | Username accepted; password required |
| 425 | Cannot open data connection |
| 450 | File unavailable |
| 500 | Syntax error |
| 530 | User not logged in |
Data Connection Establishment
FTP establishes the data connection as follows:
- The client performs a passive open using an ephemeral port.
- The client informs the server of this port using the PORT command.
- The server performs an active open using Port 20.
- The file transfer begins.
Data Representation in FTP
FTP allows different ways of representing transferred data.
1. File Structure
- Continuous stream of bytes
- Default structure
2. Record Structure
- File divided into records
- Used mainly for text files
3. Page Structure
- File divided into pages
- Each page has a page number and header
File Types Supported
FTP supports different file formats.
| Type | Description |
|---|---|
| ASCII | Text files |
| EBCDIC | IBM character format |
| Image | Binary files (images, executables, etc.) |
Transmission Modes
FTP provides three transmission modes.
| Mode | Description |
|---|---|
| Stream Mode | Continuous stream of bytes (default) |
| Block Mode | Data sent in blocks with headers |
| Compressed Mode | Data compressed before transmission |
Types of File Transfer
FTP supports three major operations:
1. Retrieve (Download)
- Server → Client
- Uses RETR command
2. Store (Upload)
- Client → Server
- Uses STOR command
3. Directory Listing
- Server sends directory contents
- Uses LIST command
Working of FTP
- Client establishes a control connection (Port 21).
- User logs in using USER and PASS commands.
- Client specifies file type, structure, and transmission mode.
- Client requests file transfer using RETR or STOR.
- A data connection (Port 20) is established.
- File is transferred.
- Data connection closes after transfer.
- Control connection remains open for additional operations.
- User issues QUIT command.
- Control connection closes.
Advantages of FTP
- Reliable file transfer using TCP.
- Supports upload and download of files.
- Handles different file formats.
- Supports file management operations (rename, delete, create directories).
- Efficient due to separate control and data connections.
- Suitable for transferring large files.
Limitations of FTP
- Username and password are transmitted in plaintext.
- File contents are transferred without encryption.
- Vulnerable to eavesdropping and attacks.
- Less secure than modern secure file transfer protocols.
To improve security, SSL-FTP (FTPS) or SSH-based file transfer (SFTP) can be used.
Summary
| Feature | FTP |
|---|---|
| Full Form | File Transfer Protocol |
| Layer | Application Layer |
| Transport Protocol | TCP |
| Control Port | 21 |
| Data Port | 20 |
| Architecture | Client–Server |
| Connections | Two (Control and Data) |
| Main Purpose | File Transfer |
| File Operations | Upload, Download, Directory Listing |
| Security | Plaintext (can be secured using SSL/TLS or SSH) |

Comments
Post a Comment