Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deeply understand FTP protocol

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to deeply understand the FTP protocol, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Foreplay

Let's take a closer look at the FTP protocol.

File transfer Protocol FTP (File Transfer Protocol) is the most widely used file transfer protocol in the Internet. FTP uses interactive access, allowing customers to specify the type and format of the file (such as indicating whether to use an ASCII code) and allowing access to the file (such as the user who accesses the file must be authorized and enter a valid password).

File transfer protocols include FTP based on TCP and simple File transfer Protocol TFTP based on UDP. They are a large category of file sharing protocols, that is, copying the whole file. Its characteristic is that if you want to access a file, you must first get a local copy of the file. If you want to modify the file, you can only modify the copy of the file, and then send the modified file back to the original node.

Basic working principle of FTP

FTP shields the details of each computer system, so it is suitable for transferring files between any computer in a heterogeneous network. FTP only provides some basic services of file transfer. It uses TCP to transport services reliably. The main function of FTP is to reduce or eliminate the incompatibility of processing files in different systems.

FTP uses the client-server model, and a FTP server process can serve multiple client processes. The FTP server consists of two main parts: a main process responsible for accepting new requests, and several subordinate processes responsible for processing a single request. Working steps of the main process

Open the familiarity port (21) so that the client process can connect to

Wait for the client process to send a connection request

Start the slave process to process the connection request sent by the client process, and the slave process ends after processing the request. During operation, the slave process may create some other child processes as needed.

Return to the waiting state and continue to accept requests initiated by other client processes. The processing of the master process and the slave process is concurrent.

The working condition of FTP

The FTP control connection remains open throughout the session and is used only to send connection / delivery requests. When the client process sends a connection request to the server, look for the well-known port 21 of the connection server process, and tell the server process its own port number to establish a data transfer connection. Then, the server process uses its own well-known port 20 to establish a data transfer connection with the port number provided by the client process. FTP uses two different port numbers, so the data connection and control connection will not be confused.

1.1 FTP data representation

FTP protocol provides a variety of options for control protocol transmission and storage, and a choice must be made in the following four aspects.

File type: ASCII file (default) / image file type (binary) / local file type (used to transfer binary data between hosts with different byte sizes)

Format control: this option applies to ASCII type files, non-printing (default selection, file does not contain vertical format information) / remote login format control

Structure: file structure (default selection, file is considered to be a continuous byte stream, there is no internal file structure) / record structure (for text files)

Transmission mode: stream mode (mode selection, files are transferred by byte stream), for file structure, the sender prompts to close the data connection at the end of the file, for record structure, there are dedicated two-byte sequence code recording end and file end) / block mode (files are transferred in a series of blocks with one or more first bytes in front of each block) / compression mode

1.2 FTP commands and responses

Commands and responses are transmitted in the form of NVT ASCII codes on the control connection between the client and the server. This requires that the CR, LF pairs (that is, each command or reply) be returned at the end of each line. These commands are 3 or 4 bytes of uppercase ASCII characters, some of them with option parameters. More than 30 FTP commands are sent from the customer to the server. The following are some of the more commonly used commands:

The responses are all 3 digits in the form of A S C I I codes, followed by message options. The reason is that the software system needs to decide how to respond according to the digital code, and the option string is oriented to manual processing. Since customers usually output digital responses and message strings, an interactive user can determine the meaning of the response by reading the message string (without having to remember the meaning of all the digital answer codes).

2 FTP working mode

FTP has two working modes, active mode (PORT) and passive mode (PASV). These two modes are based on the "perspective" of the FTP server, more generally speaking: when transmitting data, if the server is actively connecting to the client, it is the active mode; if the client is actively connecting to the server, it is the passive mode. For a more specific explanation of active mode and passive mode, please click: diagram the active mode and passive mode of FTP as well as the client settings.

3 questions about FTP classics

3.1How do I know the end of FTP transferring a file?

This is a classic question, and it is also a question asked in an interview. As mentioned earlier, the general transfer mode is streaming, and the end of the file is marked by closing the data connection, which means that a new data connection is established for each file transfer or directory list. The general process is as follows:

It is precisely because the customer issues a command to establish a data connection, so the data connection is established under the control of the customer.

Customers typically choose a temporary port number for their data connection port on the client host. The customer issues a passive open from the port.

The client uses the P O RT command to send the port number from the control connection to the server.

The server receives the port number on the control connection and issues an active open to the port on the client host. The data connection side of the server has been using port 20.

Figure 27-4 shows the connection status when step 3 is performed. Assume that the temporary port used by the customer to control the connection is 11 7 3, and the temporary port used by the customer for data connection is 11 7 4. The command issued by the customer is the PORT command, whose arguments are decimal numbers in six ASCII separated by commas. The first four digits indicate the IP address on the customer to which the server will actively open (140.252.13.34 in this case), and the last two digits indicate the 16 bit port address. Because the 16 bit port address is obtained from these two numbers, the value in this case is 4 × 256 + 150 × 1174.

Figure 27-5 shows the connection status when the server issues an active open to the customer's data connector. The endpoint of the server is port 20.

The server always performs an active opening of the data connection. Usually the server also performs a proactive shutdown of the data connection, unless the client is required to close the connection when the client sends a streaming file to the server (it notifies the server of the end of the file).

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report