Full knowledge of FTP from TCP/IP model

Source: Internet
Author: User
Tags ack ftp ftp connection file transfer protocol ftp protocol port number

1. FTP protocol Overview

FTP is the abbreviation for File Transfer Protocol (Transfer Protocol). FTP is a specific application of TCP/IP, it works on the seventh layer of the OSI model, on the fourth layer of the TCP model, the application layer, using TCP transmission instead of UDP,FTP connection is reliable, and it is connection-oriented, which provides a reliable guarantee for data transmission.

The FTP operating mode is similar to the client/server model. Unlike most other TCP applications, FTP uses two TCP connections between the client and the server--control the connection and the data connection, the control connection exists in the whole process of the client interacting with the server, and the data connection is created only when there is a file or directory transmission, and is closed after use. The control connection is used to send instructions to the server and wait for the server to respond, and the data connection is used to establish the data transfer channel.

Two connection modes of 2.FTP ―――port mode and passive mode

FTP uses a different TCP port number, depending on whether you are using port mode or passive mode.

2.1 FTP Port Mode

The FTP steps for Port mode are as follows:

1, the client sends a TCP SYN (TCP synchronization) packet to the server segment well-known FTP control port 21, the client uses the temporary port as its source port;

2, the server sends the SYN ACK (synchronous confirmation) package to the client, the source port is 21, the destination port is the temporary port which uses on the client end;

3, the client sends an ACK (confirm) package, the client uses this connection to send the FTP command, the server side uses this connection to send the FTP reply;

4. When the user requests a list request or initiates a request to send or accept a file, the client software uses the Port command, which contains a temporary port, and the client expects the server to use this temporary port when opening a data connection; The port command also contains an IP address, this IP address is usually the client's own IP address, and FTP also supports the third party (third-party) mode, the third party mode is the client told the server side to open the connection with another host;

5, the server to send a SYN packet to the client's temporary port, the source port is 20, the temporary port for the client in the port command sent to the server side of the temporary port number;

6, the client to the source port for the temporary port, the destination port for 20 to send a SYN ACK packet;

7, the server side sends an ACK packet;

8, the host sending data to send data in this connection, the data in TCP segment (Note: segment, layer 4th of the PDU) in the form of sending (some commands, such as stor to send data, RETR said the server to send data), these TCP segments need each other ACK acknowledgement ( Note: Because the TCP protocol is a connection-oriented protocol;

9, when the data transmission is completed, the host sent the information to a fin command to end the data connection, this fin command requires another host to ACK confirmation, another host also send a fin command, the fin command also needs to send data host to ACK confirmation;

10, client end, the client to the fin command to close a control connection, the server to ACK packets to confirm the fin of the client, the server also sent its fin, the client with ACK to confirm.

The following are the first steps of the FTP port mode:

The following is a reference fragment:
/==================================\
||
| [FtpClient] [ftpserver]|
||
| (tcp:21 connection initialization, control port) |
| syn|
| Portxxxx---------------------->port21[tcp]|
| syn+ack|
| portxxxx<----------------------port21|
| ack|
| Portxxxx---------------------->port21|
||
| (Control action: User column directory or transfer file) |
||
| port,ip,portyyyy|
| Portxxxx--------------------àport21|
| portseccussful|
| portxxxx<----------------------port21|
| list,retrorstor|
| Portxxxx---------------------->port21|
||
||
| (tcp:20 connection initialization, data port) |
| syn|
| portyyyy<----------------------port20|
| syn+ack|
| PORTYYYY---------------------->port20|
| ack|
| portyyyy<----------------------port20|
||
||
| (Data manipulation: transmission) |
| data+ack|
| portyyyy<--------------------->port20|
|.|
|.|
|.|
||
\==================================/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.