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:

  1. Control Connection
  2. 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 ConnectionData 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:

CommandPurpose
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

CodeMeaning
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:

  1. The client performs a passive open using an ephemeral port.
  2. The client informs the server of this port using the PORT command.
  3. The server performs an active open using Port 20.
  4. 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.

TypeDescription
ASCII    Text files
EBCDIC    IBM character format
Image    Binary files (images, executables, etc.)

Transmission Modes

FTP provides three transmission modes.

ModeDescription
Stream ModeContinuous stream of bytes (default)
Block ModeData sent in blocks with headers
Compressed ModeData 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

  1. Client establishes a control connection (Port 21).
  2. User logs in using USER and PASS commands.
  3. Client specifies file type, structure, and transmission mode.
  4. Client requests file transfer using RETR or STOR.
  5. A data connection (Port 20) is established.
  6. File is transferred.
  7. Data connection closes after transfer.
  8. Control connection remains open for additional operations.
  9. User issues QUIT command.
  10. 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

FeatureFTP
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

Popular posts from this blog

Computer Networks PCCST501 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Computer Networks

Introduction to Local Area Network (LAN)