FTP works in the application layer of the TCP/IP model, based on the transport protocol is tcp,ftp between the client and the server connection is reliable, connection-oriented, for the transmission of data provides a reliable guarantee.
Key Features of ftp:
1. A control connection is a communication link that is built between the client protocol interpreter and the server protocol interpreter for exchanging commands and responses.
2. A data connection is a full-duplex connection that transmits data. Transfer data can occur between DTP and customer DTP in the server data transfer process, and can also occur between DTP of two servers.
File type: the
1.ASCII code file type (default selection), transmitted via data connection in the form of NVT ASCII code;
2.EBCDIC file type. The text file transfer method requires that both ends are EBCDIC systems;
3. image file type (also become a binary file type), the data sent form is presented as a continuous stream of bits.
Data:
1. Document structure (file Structure) byte stream, no structure;
2. Recording structure (record Structure) files are divided into records for use in text files;
3. Page Structure files are divided into pages, with page numbers and page headers per page. Random access or sequential access is possible.
Transmission mode:
The FTP transfer mode has flow mode, block mode, and compression mode:
1. Stream mode: Data is transmitted as a byte stream
-Record structure
-File structure
2. Block mode: The file is delivered as a block with its own head section. Header byte includes 16-bit count field and 8-bit description sub-code
3. Compression mode: In compression mode, because the data is compressed, there are many advantages for increasing the bandwidth.
Structure of block-mode header bytes
Description of the bit tag that describes the sub-code in the description sub-byte
Client-server model in FTP
FTP client and server to establish a dual connection, one is to control the connection, one is the data connection.
Control connection: NVT ASCII
Data connection: File type, data structure, transmission mode
The reason for a double connection is that FTP is an interactive session system, and each time a client invokes FTP, a session is established with the server, and the session is maintained with a control connection.
Each request by the client, the server and the client to establish a data connection, the actual data (such as file) transmission, once the data transfer is complete, the connection is revoked, but the control connection still exists, the client can continue to issue commands.
The customer can either revoke the control connection (Close command) or exit the FTP session (quit command).
The implementation of the FTP server is done by a set of FTP processes.
Server FTP process: consists of the Protocol interpreter PI and the data transfer process DTP.
Client FTP process: Consists of pi, DTP, and user interface.
The use of separate connection modes for transmission and control has the following three advantages:
1. Make the FTP protocol simpler and easier to implement, such as the control connection can be directly implemented by the Telnet protocol, the FTP data connection will not be confused with the FTP command;
2. After the end of the data connection, the control connection is still retained, it can be used in the new transmission connection;
3. The sender and receiver can reach the command transmission function by notifying the other party with the end of the file on the data connection when all the data arrives.
FTP uses the Telnet protocol to control the connection.
Communication:
FTP uses a client/server model that involves five processes and two related.
The server first runs a local FTP master service process, and when the client user enters the open or FTP command, the client specifies a remote computer, establishes a client-side control process, and the local application becomes an FTP client, establishing a semi-correlation with itself.
The client then uses TCP to establish a control connection to the FTP server on the specified computer.
After the server receives a request from the client, it derives a server control process that establishes a control connection with the client control process, which is related to both sides entering the session state.
When the client is transferring data, it derives a client data transfer process and passively opens on a non-default port, and the client sends the port number to the server control process with port by controlling the connection.
After the server control process is received, a server data transfer process is derived, the process establishes its own semi-correlation (20), and sends a connection request to the client data process, which is related to the client transfer process and establishes data transfer between the two parties.
After the data transfer is complete, the connection is closed and the transfer process ends, but the control process still exists, and then the new data transfer service can be re-initiated.
FTP Command and response
FTP commands are primarily used to control connections and can be implemented directly using the Telnet protocol, so the ftp command with telnet command includes interrupt process, Telnet sync signal, query server, telnet command with options, and so on.
Commands are transmitted in NVT ASCII, requiring CR, LF pairs at the end of each line.
The FTP response is a 3-bit number in the form of ASCII code, and the response is transmitted in NVT ASCII, requiring the return of CR, LF pairs at the end of each line.
Use of anonymous ftp:
From the previous explanation, the use of FTP must first log on with the Telnet protocol to obtain the appropriate permissions of the remote host to upload and download files.
The local host must have a user ID and password to obtain the appropriate authorization from the remote computer, otherwise it will not be able to transfer files, many FTP hosts on the Internet, and it is not possible to require each user to have an account on each host.
Anonymous FTP solves this problem by eliminating the need for the local host to become a registered user of the remote computer.
anonymous FTP mechanism:
The remote computer establishes a user special ID named anonymous so that anyone on the Internet can use the user ID to download the file anywhere, without becoming a registered user.
The anonymous FTP host connection is used in the same way as a common FTP host, except that anonymous must be entered when a user ID is required, and the password can be any string that the client likes.
FTP File Transfer Protocol