File Transfer Protocol (FTP)
FTP is divided into two connections: the command connection and the data connection.
Command Connection: Primarily used for sending control messages.
Data Connection: Used for sending actual file data.
FTP Command Connection (port 21)
The client initiates a TCP connection to start a session.
FTP commands are usually textual and consist of verbs.
Examples include
USER,PASS,CWD,LIST,RETR,STOR, andREST.Typical FTP responses include:
331Username OK, password required.230Login successful.125Data connection already open; transfer starting.425Can't open data connection.452Error writing file.
FTP Response Codes
1xx: Positive preliminary response.2xx: Positive completion response.3xx: Positive intermediate response.4xx: Transient negative completion response.5xx: Permanent negative completion response.
FTP Data Connection (port 20)
FTP client initiates the connection on port 20. It operates separately from the command connection, which allows it to transfer files.
FTP Data Connection Modes: Active vs. Passive
Active Mode (PORT):
The command format is
PORT h1,h2,h3,h4,p1,p2.It suggests that the client listens on IP address
h1.h2.h3.h4and port numberp1*256+p2for a data connection.The FTP server then initiates the connection to this specified port.
Passive Mode (PASV):
Once the server listens and is ready for a connection, it informs the client about the IP and port details.
FTP Flow
For both modes, the flow is as follows:
CWD srccommand is sent by the client.200response is a positive completion.In Active mode, the
PORTcommand specifies where the server should connect. In Passive mode, thePASVcommand asks the server where to connect.LISTcommand is issued to get a list of files/directories.150indicates the start of a file transfer.Data is then transmitted.
226indicates the completion of the file transfer.
Last updated