File Transfer Protocol (File Transfer Protocol, FTP)

xiaoxiao2021-03-06  112

1 Introduction

The target of FTP is to increase the sharing of files, providing non-direct use of remote computers to transfer data to users transparently and efficiently. Although we can also manually use it, its main role is for the process of use. It is best to read the TCP protocol standard specification and Telnet protocol standard specification before reading this article.

2. Overview

In this section we will discuss some problems on the surface, please refer to TCP and Telnet reference. Let's introduce it first.

(1) Byte size, two bytes in the ftp: logical byte size and byte size for transmission. The latter is usually 8 bits, while the former can not necessarily be. The transmission byte does not have to be equal to the logical byte size, and it is not necessary to explain the data structure. (2) Control connection is a communication link that is built between user-pit and server-pi for exchange commands and answers. (3) Data connection is a full-duplex connection to transmit data. Transmission data can occur between the server DTP and the user DTP can also occur between the two servers DTP. (4) DTP: Data Transmission Process (DTP) Establish and Manage Data Connections, DTP can be active or passive. (5) EOR represents the recording end. (6) NTV represents a network virtual terminal, and its definition is consistent with the definition in the Telnet protocol. (7) NVFS represents a network virtual file system. (8) FTP can transmit discontinuous files, part of these files called pages. (9) PI represents the protocol interpreter. (10) The server DTP represents a transmission process, which is usually in the "active" state, which establishes a data connection with the listening port, which can also provide parameters for transmission and storage, and transmit data according to the command of the PI. Of course, DTP can also transfer "passive" state. (11) The server ftp process, which is working with the user's FTP process, which consists of PI and DTP. As for the user FTP process, it consists of PI, DTP, and user interface. The picture below is a schematic of FTP service:

------------------ | / ------- / | || User || --- || Interface | <---> | User | | / ------- / | --- ------------ | | | | / ---- / | ftp command | / --- v --- / | | | Server | <--------------------> User || || Pi || FTP Response || Pi || | / ---- / | | / ------- / | | | | | | | ------------ | / - V - / | Data | / --- V --- / | | ------> || Server | <--------------------> | User || ----- | System | || DTP || Connection || DTP | <---> | File System | ------------ | / ---- / | | / ----

--- / | ---------------------------------- Server FTP User FTP

Note: The data connection is two-way, it does not exist throughout the time. In the above picture, the user Pi starts to control the connection, and the control connection is very similar to the Telnet protocol. At the beginning, the standard FTP command is generated by the user Pi and transmits it to the server process through the control connection. The server PI returns a standard response to the user PI. The ftp command specifies the data connection parameters and file system operations. User DTP is listened to a particular data port, and the server starts data connection and starts data transfer at the specified parameter. The data port does not have to start the FTP command, but the user or user FTP process must determine it listens on the specified data port. This data connection is a full duplex.

In another case, the user may wish to transfer files between two hosts, not two local hosts. The user establishes a control connection between two hosts and planning the data connection. In this manner, the control information is obtained by the user PI, but the data is transmitted between the server DTP. Here is an example:

Control ----------------- Control ------------> | User - FTP | <----------- - | | User - Pi | | | | "C" | | V ----------------- V --------------- --------------- | Server - FTP | Data Connections | Server - FTP | | "A" | <------------- -----------> | "B" | -------------- Port (a) port (b) ---------- -----

The protocol requires data transfer to turn on the control connection during processing. After the FTP service is complete, the control connection is aborted by the user, and the server is specifically operated. If the control connection is turned off when the command is not received, the server will turn off the data transfer. FTP and Telnet have a touch of contact, and FTP uses the Telnet protocol to control the connection, there are two ways to achieve the purpose: the user PI or server PI can implement the function of Telnet protocol in its own process; the second method is to use the system Telnet module. In fact, the dependence on the Telnet protocol is not much dependent, even if it is re-implemented, the amount of code is not large.

3. Data transfer function

Data connection only transmits data, controls the connection to transfer commands and responses. Several commands are about transmitting data between hosts. The data transfer is basically independent of physical structure, but if the flow transfer is related to the file structure in the compressed transmission mode, the properties of the file are related to the indication type.

3.1. Data representation is delivered between storage settings between the host. Because the data stored mode of the two systems is different, it is necessary to convert it. There is a problem that is represented by ASCII when transmitting text. When carrying binary transmission, there will be different problems with different systems to specify different systems. The system is 7 bits, and some systems may be 32 bits, which also requires conversion. Data representation and transmission model functions are required, but FTP provides not much features in this area, and that part of the FTP provides the user to implement itself. 3.1.1. Data type

The data representation is the type of representation specified by the user, which may be implied, or the user is specified. Please note that the length of logical byte is different from the physical byte length.

3.1.1.1. ASCII type

This is the default type of all FTPs that must be implemented, which is used to transfer text files, which is more convenient when transmitting EBCDICs between hosts, no use of ASCII types. The sender converts the internal representation into an NVT-ASCII format, and the recipient is reversed to receive data. Depending on the NVT standard, the sequence is used at the end of the line. NVT-ASCII is 8-bit. The format parameters of ASCII and EBCDIC are discussed below.

3.1.1.2. EBCDIC type

It is a data type that transmits data between the host as another method of ASCII. EBCDIC and ASCII are very like, there are some differences only on the type of functional description. The end of the line is very small.

3.1.1.3. Image type

The data transmitted under this type is regarded as a continuous bit, and the sender is packed to the 8-bit transmission byte. Because the need to be fill the transfer data, the padding bytes are all 0, and the pads must be used when the file structure is used, and to be marked so that the receiver is filtered out. It is used to transmit binary data and efficiently transmit and store files, so all FTPs must also be implemented. 3.1.1.4. Local Type

You can also specify logical byte size with decimal. If the physical byte size is different, the physical data is packaged directly into logical bytes, and no fill is not used. The recipient performs conversion based on the logical byte size and the storage characteristics of the unit. The transmission must be repeatable, that is, the same parameters as the same file must be the same.

3.1.1.5. Format Control

ASCII and EBCDIC have an optional parameter that illustrates file vertical format control, the following data indicates that the type is defined in the FTP. Character files may have three uses, print, store, or leave later. If it is used for printing, the host must know the representation of vertical format control, if stored or wait for later processing, it is also necessary to retain file format. If you are transferring back to the local host after processing over the remote host, there is no trouble when the remote host is processed. This requires the addition of new parameters in ASCII and EBCDIC format.

3.1.1.5.1. Non Print

The second parameter is not specified is that it is the default value. It must be accepted for all FTPs. If the transferred file is used for printing, the default value of the boundary and interval is used. Usually it is not used for printing, and for saving files or execution files.

3.1.1.5.2. Telnet format control

The file includes ASCII / EBCDIC vertical format control, which allows printing normally.

3.1.1.5.3. Carriage Control (ASA)

The file contains the ASA (Fortran) vertical format control character. In the rows formed in accordance with the ASA standard, the first character is not printed, it is used to determine the amount of paper before playing. Here is the defined ASA character:

Blank: Move down 1 line; 0: Move 2 line down; 1: Move to the next page; : Do not move

The printer must be able to determine the end of the structure. If the file itself has a record structure, there is no problem, if not, it is used to distinguish the print line, but these format tags have been used by the ASA control character.

3.1.2. Data Structure

In addition to different data types, FTP also allows different file structures, the following is three file structures:

File Structure: There is no internal structure in the file. The file is considered to be a binary stream; a record structure: file is composed of a series of records; page structure: file is composed of different index sheets.

If the STRU command is not used, the file structure is the default value. The structure of the file affects the transmission model, storage, and data representation. The original property is related to the host, and the different machines will save the file in their own way. The host must be recognized by each other when transmitting files between different hosts. Some of the files on the host are bytes, some are recorded, and there is a problem when transmitting. Then you have to convert internal conversions at the recipient. When performing conversion, you need to distinguish the boundaries of the records, use in ASCII, used in EBCDIC as a separator. This implementation method must be guaranteed to be reversible.

3.1.2.1. File structure

If the STRU command is not used, the file structure is the default value. There is no default value in the file structure, and the file is considered to be a continuous byte string.

3.1.2.2. Recording structure

For text files, the recording structure must be that all FTP implementations must be. The recording structure file is composed of continuous records.

3.1.2.3. Page structure

The file is used in non-continuous use of the page structure. This file is called a random access file. These files sometimes appear as a whole or part of the information. In FTP, a part of the file is called a page. To provide different page sizes and related information, each page is sent with page headers. The page is as the domain:

The length of the header includes this byte of the page length, the unit is byte, the minimum length is 4 Page Index indicates the location of this portion in the original file, it is not a logical byte number in the data length page data, The minimum value is the type of page type page. There are several types: 0 = not page, indicate the transfer structure, the header must be 4, the data length must be 0; 1 = usual page, the normal type of the usual page file without control information; 2 = Description sub-page, used to transmit a description of the overall file; 3 = Access control page, page file header domain, including page-level access control information, the length of the header must be 5

Optional domain provides control information per page

All domains are in size in size, and the logical byte length is specified by the TYPE command. If the read version is consistent with the start version number, the file access must be done with the same parameters. If the parameter is the same, the FTP implementation is the same as the content you have to ensure that the content acquired.

3.2. Establish data connection

The transfer data mechanism includes establishing a connection selection data parameter. The user and server DTP have the default data port. The user process default data port is the same as the control connection port. Server process default data ports and control connection ports. The transmission byte size is 8-bit bytes. This byte is an actual transmission byte, but does not represent data representative in the host. The passive data transfer process receives data in the data port, and the FTP request command determines the direction of the data transmission. After receiving the request, the server connects the data connection of the port. When the connection is established, the transfer is transmitted between the DTP, and the server Pi returns the user PI. The FTP implementation runs a default data port, and the user PI can change the default port.

The port command may change the port, and the user may wish to perform other operations on a third-party host, and the user PI needs to establish a connection on the two server Pi. A server is told to listen to another server request. User PI notifies another server's data port through the port command. Finally, both parties send the corresponding transfer command. Typically, the server is responsible for supporting data connections, initializing and turning off, unless the user DTP requires closing connections in transmission mode. The server closes the data connection in the case:

1. The server ends the transmitted data, and the transfer is subtracted by EOF; 2. The user sends an ABORT command; 3. The user changes the port; 4. Control connection is closed; 5. If you have an unrecoverable error. 3.3. Data connection management

Default data connection port: All FTPs must support the default data connection, only the user PI can initialize the use of non-default ports.

Determine non-default data port: User Pi can specify a non-default port using the port command, which requires the server to determine non-default data ports at PASV. The connection is determined by the two addresses, so changing the part of the address changed.

Denual data connection: When using a streaming data transfer model, the file ends pass through the closing connection indication. If you want to transfer multiple files, you will have trouble, and the solution has two, one is to determine the non-default port, and the other is to use another transmission mode. In terms of transmission mode, the stream transmission mode is unsafe, so it is not possible to determine whether the connection is temporarily or permanently closed. Other transmission modes do not represent file structures by closing the connection, they can determine the transfer structure via the FTP command. So use these transmission modes can be transmitted in the case where the connection is kept.

3.4. Transfer mode

There are three transmission modes: a formatted data format and considers the restart process; a compressed data; one is not processed (small processing) transmission. All data transfer must end with an EOF, which can be explicitly given, or by turning off the connection. For record files, all EOR is explicit, including the last record. For files transmitted in a page structure, use the "Last page" to end. From here, the byte we mentioned below refers to "Transmission bytes".

In order to conduct standardized transmission, the transmit host must convert the internal representation of the end of the line or the record to the transmission mode and the file structure designated, and the reception is reversed. The record count domain of the IBM mainframe may not be identified for other hosts, so the recording end tag is transmitted in stream mode with a double-byte control code, and transmits in the block or compression mode. The rows of ASCII or EBCDIC are ended or indicated. Such a conversion takes time, so the same system is used in a binary or stream when transmitting a text file. Here is the transfer mode defined by FTP:

3.4.1. Flow mode

Data is transmitted in the form of a word stream. The type of representation is not limited, allowing the recording structure. The recording structure file EOR and EOF are represented as a double-byte control code. The first byte is all 0, and the latter byte is a escape character. When the second bit value is 1 indicates the EOR, indicating EOF at 2, if the EOR and EOF are indicated, the value is 3. Double-byte transfer must be used when all 1 bytes are transmitted as data transmission, where data is saved within the second byte. If it is a file structure, close the connection by the sender indicates EOF, and all data received is the file content.

3.4.2. Block mode

The file is transmitted in block, and the block has its own head section. The header is included including the count domain and the descriptor subcode. The count domain describes the number of bytes of data blocks, and the descriptor is defined below: EOF, EOR restart tag or doubt error data. Doubt error data is not to perform error control, it is to transmit specific data between the site, when transmitting local errors (such as hard disk errors), but it can be pointed out that this data may be wrong. In this mode, the recording structure can be used, or the corresponding data representation can also be used. The structure of the header is shown below:

Description sub-8-bit byte count 16 bits

The description sub-code is described by a bit tag in the sub-byte, and below is the four code already specified and its meaning:

Code Significance 128 The end of the data block is the end of the EOOR 64 data block is an EOF 32 data block has doubt error 16 data block is a resumption mark.

With this coding, there may be multiple descriptive sub-coding conditions for a particular block, and the required bits must be all set. The restart tag included in the data stream, which as an 8-bit integer represents the printable byte of the language on the control connection, but must not appear. For example, you want to transfer 6-byte tags, below: Descrptr Code = 16 Byte Count = 6

Marker 8 Marker 8-bit Marker 8

Marker 8 Marker 8-bit Marker 8

3.4.3. Compression mode

There are three information that requires delivery: regular data is transmitted in byte string; compressed data, including copying and filters; control information, transmitted in two essential characters. If there is n (> 0 but less than 127) regular data transfer, plus one byte in front of the data, this byte is the highest bit of 0, and the numerical value represented by other bits is equal to N. As shown below:

1788 - - - - - - - - - - - - - - - - - - - - - - - | 0 | N | | D (1) | ..... | D (n) | - - - - - - - - - - - - -

To compress a data bit D, the N reply string is transmitted, transfer with two bytes, as shown below, it represents a compressed byte:

2 6 8 - - - - - - - - - - - - - - - - - | 1 0 | n | | d | - - - - - - -

A string n-sharpened byte can be compressed into one byte, and the filter bytes are different depending on the representation. If the type is ASCII or EBCDIC, the filter byte is 0, if it is an image or a local type, it is 0. Below is the filter byte:

2 6 - - - -

The escape sequence is a double byte, one full 0, and the latter is defined in block mode descriptor subcoding. Description subcodes are the same as the meaning in block mode, which acts on bytes in the backed string. Compression mode is good for increasing bandwidth (because data is compressed).

3.5. Error recovery and restart bit loss and data error are the error control of this layer is responsible by TCP. The restart is a method for the user's processing system (including operating system, network, etc.). The restart process is only available for block and compression mode, which requires the sender to add a specific tag in the data stream, and the tag is only meaningful to the transmitter, but the content is the language that controls the connection. The marker can represent any point of one bit count, record counts, or any point that can be marked with the number of data. If the recipient also supports resumption, this tag will be saved in the receiving system. After the system failure is restarted, the user can restart the data transfer according to the original tag, which is the breakpoint process of breakpoints we are familiar with. The receiver receives a segment of data and then records it. If the sender fails, it will transmit the corresponding data later. Specifically, there is not much here.

4. File transfer function

The channel from the user PI to the server is built between the user to the tag server. The User Protocol Interpreter is responsible for sending commands and interprets the received response; the server PI interpret command, send a response, and guide the DTP to establish a data connection and transmit data. If the second part of the data transmission is the user DTP, it controls it through the internal protocol of the user FTP host; if the second part is the server DTP, it is controlled by the user PI.

4.1. Ftp command

4.1.1. Access Control Command

The following command specifies the access control tag (command code in parentheses):

Username (User)

The parameters are tagnet strings that mark users. The user tag is a must-have, this command is usually the first command that controls the first one, and some hosts also require passwords and accounts. The server can receive a new user command at any time to change access control and / or account information. This can restart the login process, so the transmission parameter is unchanged, and the file transfer in progress is completed under the past access control parameters.

Pass (pass)

The parameter is a Telnet string that tags the user password. This command is tight with the user command, where it is an indispensable step of completing access control. So the password is an important thing, so it cannot be displayed, the server side does not have a way to hide the mouth, so this task has to be completed by the user FTP process.

Account (ACCT)

The parameter is a telnet string that tag the user account. This command does not need to be related to user, some sites may require an account to log in, and others can limit the permissions of the account. In the latter case, this command can be sent at any time. The difference between the response can distinguish between the situation: When the login needs account information, the response to the pass command is 332. Also, if the account information is not required, the response to the pass is 230. If the account information is required in the future, the server will return 332 or 532, which is to see whether it is saved or rejects this command.

Change Work Directory (CWD)

This command enables users to work in different directories or data sets without changing its login or account information. Transmission parameters are also constant. The parameter is generally a directory name or a file collection related to the system.

Back to the previous point catalog (CDUP)

This command requires the system to implement the directory tree structure, its response and the same CWD.

Structure loading (SMNT)

This command enables the user to load another file system data structure without changing the login or account information. Transmission parameters are also constant. The parameter is a file directory or a set of files related to the system.

Reinitialization (Rein)

This command terminates USER, writes all I / O and account information, but not in progress. Reset all parameters, control the connection to open, you can start the user command again.

Exit Login (QUIT)

This command terminates the user. If there is no data transfer, the server shuts down the control connection; if there is data transmission, the server closes the control connection after obtaining the transmission response. If the user process is transferring data to different USER, you can use Rein if you don't want to close each USER and then open it. Unexpectedly on control connection, can cause server operation abort (Abor) and quit. 4.1.2. Transmission parameter command

All data transmission parameters have default values. The server must record the default value, and after the FTP service request can be sent in any order. The command transfer parameters below:

Data port (port)

The parameter is the data connection port to be used, usually without command response to this. If you use this command, you want to send 32-bit IP addresses and 16-bit TCP port numbers. The above information is transmitted in 8 bits as a group, comma-separated decimal transmission, as in the following example:

Port H1, H2, H3, H4, P1, P2

Where H1 is the highest 8 digits of the IP address.

PASV)

This command requires the server DTP to listen in the specified data port, and enter the passive reception request, the parameter is the host and port address.

Representation type (TYPE)

The parameter specifies the type. Some types require a second parameter, the first parameter is defined by a single Telnet character, the second parameter is the decimal integer specifies bytes, and the parameters are separated. Below is a format:

/ / A - ascii | | n - non-print | -> <- | TELNET FORMAT EFFECTORS E - EBCDIC | | C - Carriage Control (ASA) / / i - Image L - Local Byte size

The default representation is an ASCII non-printing character. If the parameter has not changed, only the first parameter is changed later, then the default value is used.

File Structure (STRU)

The parameter is a Telnet character code specifies the file structure. The following is the code and its meaning:

F - file (non-recorded structure), it is the default value R - record structure P - page structure

Transmission mode (MODE)

The parameter is a Telnet character code specified transmission mode. The following is the code and its meaning:

S - stream (default) B - block C - compression

4.1.3. Ftp service command

The FTP service command defines the file transfer or file system feature requested by the user. The parameters of this command are usually the path name, and its syntax is consistent with the servers. The recommended default is the recent specified device directory or directory. Command order usually does not limit, only "rename from" command must be "rename to", and then restart the command must be an interrupt service command. The response of the service command is usually transmitted over a data connection. Here is the specific command:

Get file (Retr)

This command enables the server DTP to transfer files in the specified path to the server or user DTP. The status and content of the file on this server are not affected.

Save (STOR)

This command allows the server DTP to receive data transferred on the data connection and saves the data in the server. If the file already exists, the original file will be overwritten. If the file does not exist, create a new file.

Single Save (STOU)

This command is similar to the Stor, this command requires the file name in this directory, and the response to this command must include the generated username.

APPE

It is similar to the functionality of the Stor, but if the file already exists in the specified path, the data is attached to the end of the original file, and if there is no new file.

Distribution (Allo)

This command is used to assign enough storage space for newly transmitted files on some hosts. The parameter is the number of logical bytes of decimal. If it is a record or page structure, a page, or a maximum size of the record, which is specified in the second parameter. The second parameter is optional, if there is it, it and the first parameter are separated by Telnet character R. After this command is in the Stor or APPE command, its role is equal to NOOP for a machine that does not need to allocate storage space. Restart (REST)

The parameter domain represents the server to restart, this command does not transmit the file, but the data after the specified point, this command should follow other FTP commands that require files to be transferred.

Rename (RNFR)

This command is the same as we used in other operating systems, but you have to specify new file names with "Rename TO". Rename (RNTO)

This command and the above command work together to rename the file.

Abandon (Abor)

This command notifies the service abort the previous FTP command and the data transfer associated therewith. If the previous operation has been completed, there is no action, returns 226. If you do not have, return 426, then return 226. Close the control connection, the data connection is not closed.

Delete (Dele)

This command deletes files under the specified path. The user process is responsible for the removable prompt.

Delete Directory (RMD)

This command deletes the directory.

Create a directory (MKD)

This command creates a new directory under the specified path.

Print Work Directory (PWD)

In response is to return the current working directory.

List (list)

The server transmits a list to passive DTP, if the path specifies a directory or a lot of files, returns a list of files under the specified path. If the path name specifies a file, the server returns the current information of the file, the parameter is empty, indicating the current working directory or default directory of the user. Data transfer is performed in ASCII or EBCDIC, and the user must confirm this. Because the file information is different due to the system, it is impossible to be automatically utilized by the program, but human users need.

Name list (NLST)

The server transmits the directory table name name to the user, the path name should specify the file group descriptor specified by the directory or other system; empty parameters refer to the current directory. The server returns the file name data stream to transmit, and or separate in the form of ASCII or EBCDIC. The information returned here is sometimes available for further processing.

Site parameter (Site)

The server is used to provide server system information, and the information is different from the system, and the format is given in the Help Site Command Answer.

System (SYST)

Used to determine the operating system running on the server.

Status (STAT)

This command returns to the control connection status, which can be sent during the file transfer, and the server returns the state of the operation. You can also send between file transfer. At this time, the command has a parameter, the parameter is the path name, and the function of this command is similar to the list of lists in the control connection. If the part path is specified, the server returns in the file name or the attribute associated with the description; if there is no parameters, the server returns status information of the server FTP process, including the current value of the transmission parameter and the connection state.

Help (HELP)

This command we have no difference in the help in the usual system, the response type is 211 or 214. It is recommended to use this command before using the USER command.

Waiting (NOOP)

This command does not generate what actual action, which only returns the server to OK.

FTP uses Telnet communication on the control connection, so there is a chance to see the relevant protocol description. The understanding of the following will be very beneficial. The following will be explained to the command response and details about the command. The ftp command can be divided into access control tags, data transfer parameters, or FTP service requests, and specific commands (such as Abor, STAT) can be transmitted over the control connection during data transfer. Some servers cannot monitor data and control links at the same time, so they have to take additional measures. Please pay attention to the following suggestions:

1. User system Insert Telnet's "Interrupt Process" information into the Telnet stream; 2. The user system sends a "SYNCH" signal for Telnet; 3. User system inserts commands (such as Abor) into the Telnet stream; 4. Server Pi After receiving IP, look for only one FTP command in the Telnet stream. 4.2. Ftp response

The response of the FTP command is to synchronize the data transfer request and the process, but also to let the user understand the status of the server. Each command must have a minimum of one response, if it is multiple, they have to distinguish. Some commands are sequential, so the failure of any of the commands can cause the beginning of the head. The FTP response consists of three numbers, followed by some text. Number with enough information Naming User PI Don't check the text know what happened. Text information is related to the server, and the user may get different text information. Text and numbers are intervals, and after text is completed with the Telnet line end. The text may be more than one line. At this time, the text must be in parentheses, and there must be information in the first line to indicate more than one line, and the last line must be marked. If you are multi-line, you can add "-" after the digital code, the last row starts with the number, followed, plus the telnet's row end value. Below is an example:

123-first line

second line

234 starting with numbers

123 last line

Everything in the triple number has certain significance, the first one determines that the response is good, bad or not complete, by checking the first place, the user process usually knows what action is going to take. If the user program wishes to understand what the problem, you can check the second bit, the third bit indicates other information. The first one has five values:

1YZ determines the preparation response

The requested operation is being initialized; waiting for an additional answer before entering the next command. This type of sound application is accepted, how to synchronize monitoring in the implementation, and the user process can now pay attention to the data connection. The server FTP process returns to 1YZ response to the first command.

2YZ determines the completion of the answer

The required operation has been completed, and a new command can be performed.

3YZ determines the intermediate response

The command has been accepted, but the required operation is stopped and the updated information is stopped.

4YZ temporarily refuses to complete the answer

Unregulated, the required operation is not executed, but the error is temporary, and the message can be sent again after a while. The user should return the beginning of the command sequence. This temporary is not good, this order means that the user process will try again again.

5yz always refuses to complete the answer

It is the difference between the temporary refusal to complete the response is that the error condition will not disappear for a while.

Let's take a look at the meaning of the second representative:

X0Z format error; X1Z This type of response is to request information; X2Z This type of response is about control and data connection; X3z is not used by the authentication and account login; X5z is not used; X5z This type of response is about file system;

The third number is further refined to the answer on the basis of the second number. In general, there is a text message after digital code. When implementing, try to use existing code, not just add new code.

Some commands such as Type or ALLO, their success does not provide task new information for the user process, so there will be no 200 response returns. If some commands are not supported for the server, but also returns to determine completion answers, so that the user process is likely to make the following command. If the required command is not an optional implementation, this command does not implement, then return to code 502. Below we list all response codes and its significance according to the order of digital order:

The specific means of response code 110 restart the tag response. In this case, the text is determined, it must be: Mark YYYY = MMMM, where YYY is the user process data stream tag, and the mmmm is a server tag. 120 Service In NNN minutes, 125 data connection has been opened, ready to transfer 150 file status, open data connection 200 command success 202 Command does not implement 211 system status or system help response 212 directory status 213 file status 214 Help information, information only For human users use 215 name system type 220 to prepare the new user service to close the control connection, you can exit the login 225 data connection open, no transmission is performing 226 turn off data connection, the request file operation success 227 Enter the passive mode 230 user login 250 Request file operation completion 257 Creating "Pathname" 331 User Name correctly, requires the password 332 When logging in, the file operation requiring account information 350 requires that further command 421 does not provide a service, shut down control connection 425 does not open the data connection 426 Close connection, abort The file operation of the transfer 450 does not perform 451 abstament request: there is a local error 452 Operation: System storage space is 500 format error, command unrecognizable 501 Parameter syntax error 502 Command does not implement 503 command order error 504 This parameter The lower command function is not implemented 530 Not logged in 532 Storage file Requires Account Information 550 Operation 551 Request operation Abort: Page type unknown 552 Request file operation abort, store allocation overflow 553 Operations: File name is not legal 5. Description

5.1. Minimum implementation

Below is the minimum implementation of the FTP server:

Type - Ascii Non-Print Mode - Stream Structure - File, Record Command - User, Quit, Port, Type, Mode, STRU, RETR, STOR, NOOP.

The default parameters for transmission are:

Type - ASCII Non-Print Mode - Stream Structure - File

All hosts will be used as the default value.

5.2. Connection

The server protocol interpreter will initialize the full duplex control connection in the port L, the user, or the user protocol interpreter, the server, and user processes should follow the Telnet protocols. The server does not provide the editing function of the command line should be responsible for all by the user. After all transfer and response, the server closes the control connection at the user's request. User DTP must listen on the specified data port, which can be the default port U or the port specified by the port command. The default data port of the server is L-1. The transfer direction and port can be determined by the ftp command. Only the user PI can change the default port. When data is transmitted between servers A and B, the user PI, C, establishes a control connection between the two server PIs. One of the servers A, receive the PASV command initialization connection when receiving the transmission service command, when the user PI receives the confirmation of the PASV command (confirmed the host ID and port), send the port to B with the port command to B. After receiving the confirmation, the user PI can send the corresponding command to A and B, B initial connection, and transmission process, command response sequences as shown below, please pay attention to time according to positions:

User-Pi - Server A User-Pi - Server B -------------------------------- C-> A : Connect C-> B: Connect C-> A: PASV A-> C: 227 Entering Passive Mode.a1, A2, A3, A4, A1, A2 C-> B: Port A1, A2, A3, A4, A1 , A2 B-> C: 200 Okay C-> A: Stor C-> B: Retr b-> A: Connect to the host A, port A At any time, the server and the user will close the connection, the other party is Hurry to read the data in the buffer, and then close the connection.

5.3. Command

This section mainly discusses the command format. Command is not sensitive to case. Commands typically consist of command code and corresponding parameters. The middle is separated by one or several spaces. The parameter domain is ended, and the server will not take any actions when the row end is not received. The format described below is to use NVT-ASCII to represent an optional parameter domain, and the default value is used if the optional parameter domain is not selected.

5.3.1. Ftp command

The following is the ftp command, where username represents the username, Password representative password, Pathname represents the path name, Host-Port represents the host port, Account-Information represents account information, Typecode represents type code, Decimal-Integer represents a decree endor, MARKER representative tag, String represents the string:

User

Pass

Acct

CWD

CDUP

SMNT

Quit

Rein

Port

PASV

TYPE

STRU

Mode

Retr

Stor

Stou

APPE

Allo

[ r ] REST

RNFR RNTO

Abor

Dele

RMD

MKD

PWD

List [ ]

NLST [ ]

Site

SYST

Stat [ ]

Help [ ]

NOOP

5.3.2. Ftp command parameters

Here is the parameter format represented by BNF paradigm:

:: =

:: =

:: =

:: = |

:: = All ASCII characters except and

:: =

:: = |

:: = Print ASCII characters, from 33 to 126

:: =

:: = ,

:: = , , ,

:: = ,

:: = Decoction integersion from 1 to 255

:: = n | t | c

:: = a [ ] | e [ ] | i | l

:: = f | r | P

:: = s | b | c

:: =

:: = any decimal integer

5.4. Command and Response Sequence

Communication between servers and users is a process of dialogue, and the user sends an FTP command, then waits for one (or more) responses to the server, and then send a new command according to the response.

The response when the connection carries a lot of information, usually, the server will return 220 response, wait for input, the user sends a new command after receiving this response, if the server does not receive the input immediately, returns 120 after 220. Some information If the server will stop working after 15 minutes is to send to the user, but the server cannot direct the user directly, the process buffer is to return the message and return to the user in the next response. The answer to the command is listed below, the first is the preparation response, the second is determined, the third is refusing to complete, and finally the intermediate response. These responses are the basis of constituent state diagrams, and the status map will be given in the next section: * Establish a connection

120

220

220

421 * login

User

230

530

500, 501, 421

331, 332

2.Pass

230

202

530

500, 501, 503, 421

332

3.ACCT 230

202

530

500, 501, 503, 421

4.cwd

250

500, 501, 502, 421, 530, 550

5.cdup

200

500, 501, 502, 421, 530, 550

6.Smnt 202, 250

500, 501, 502, 421, 530, 550

*sign out

Reein

120

220

220

421

500, 502

2.quit 221

500

* Transmission parameters

Port

200

500, 501, 421, 530

2.PASV 227

500, 501, 502, 421, 530

3.Mode

200

500, 501, 504, 421, 530

4.Type

200

500, 501, 504, 421, 530

5.stru

200

500, 501, 504, 421, 530

* File operation command

Aallo

200

202

500, 501, 504, 421, 530

2.Rest

500, 501, 502, 421, 530

350

3.stor

125, 150

(110)

226, 250

425, 426, 451, 551, 552

532, 450, 452, 553

500, 501, 421, 530

4.stou

125, 150

(110)

226, 250

425, 426, 451, 551, 552

532, 450, 452, 553

500, 501, 421, 530

5.Retr

125, 150

(110)

226, 250

425, 426, 451

450, 550

500, 501, 421, 530

6.list

125, 150

226, 250

425, 426, 451

450

500, 501, 502, 421, 530

7.nlst

125, 150

226, 250

425, 426, 451

450

500, 501, 502, 421, 530

8.appe 125, 150

(110)

226, 250

425, 426, 451, 551, 552

532, 450, 550, 452, 553

500, 501, 502, 421, 530

9.rnfr

450, 550

500, 501, 502, 421, 530

350

10.RNTO

250

532, 553

500, 501, 502, 503, 421, 530

11.dele

250

450, 550

500, 501, 502, 421, 53012.rmd

250

500, 501, 502, 421, 530, 550

13.mkd

257

500, 501, 502, 421, 530, 550

14.pwd

257

500, 501, 502, 421, 550

15.abor

225, 226

500, 501, 502, 421

* Get information commands

Zyst

215

500, 501, 502, 421

2.stat

211, 212, 213

450

500, 501, 502, 421, 530

3.help

211, 214

500, 501, 502, 421

* Other orders

Site

200

202

500, 501, 530

2.NOOP

200

500 421

6. Status diagram

Below is a simple implementation of FTP state diagram, only the first place of the response code. There are three possibilities for all commands or command sequences: Success (S), Failure (F) or Error (E). In the state diagram B represents the beginning, W represents waiting for a response. Below we give a total map, the commands that can be included are:

Abor, ALL, CWD, CDUP, SMNT, Help, Mode, NOOP, PASV, Quit, Site, Port, Syst, Stat, RMD, MKD, PWD, STRU and TYPE

1, 3 ----- -------------> | E | | ----- | ---- CMD --- - 2 ----- | B | ------------> | W | ------------> | s | --- - ---- ----- | | 4, 5 ---- ---------------> | f | - ----

The following figure can be included in the order: APPE, LIST, NLST, Rein, Retr, Stor, and STOU.

3 --- ---------------> | E | | ----- | ----- CMD --- 2 ---- | B | ------------> | W | ------------> | s | ----- --> ----- ----- | | | | | | 4, 5 ----- | | ------------ ---> | f | | 1 | ---- ------- The first picture and the second figure difference are not large, and if there is a 100 series response in the first picture. Error, and not in the second picture. Here is the renaming process:

--- RNFR ----- 1, 2 ----- | B | ------------> | W | ------ -------> | E | ---- ----- ----> ----- | | | 3 | | 4,5 | ------------------- | | | | ----- | -----------------> | S | | | 1,3 | | ----- | 2 | ----------- | | | | | | | | ---- RNTO - --- 4,5 --------> ----- | | --------> | W | ----------- -> | f | ----- ----- ---

Below is a reboot command, where cmd represents APPE, Stor or Retr.

--- rest ----- 1, 2 ----- | B | ------------> | W | ------ -------> | E | ---- ----- ----> ----- | | | 3 | | 4,5 | ------------------- | | | | ----- | -----------------> | S | | | 3 | | ----- | 2 | ----------- | | | | | | | | ---- CMD ---- - 4,5 --------> ----- | | --------> | W | ------------- > | F | ----- ----> ----- ----- | | 1 | -------- The following figure represents the login process:

1 ----- USER ----- ------------> ----- | B | --------- ---> | W | 2 -----> | E | ----- ----- ------- | ---> ---- | | | | | 3 | | 4, 5 | | | ------------------- ------- | | | | | | | | | | | | | | -------------- | | | | ---- PASS ----- 2 | ----- ---> ----- | | -------------> | W | --------------> | s | - ---- ----- ----------> ----- | | | | | | | ---- ----------------------------------------------- | 1,3 | | | | V | 2 | | ----- ACCT ----- - | ----------> ----- | | ------> | W | 4,5 ------------> | f | ----- ----- --- ------------> ---- 7. Typical FTP process

Assuming that users located in U wish to pass (next) to pass files, usually users need to use user FTP processes and server communication, the following is an example:

The local command emitted by the user is the port L of the FTP (Host) Multics Connect to the S, establishing a control connection <---- 220 service ready .

Username Doe NEED Password .user doe ----> <---- 331 username correct

Password Pass Password ----> <---- 230 USER Logged in .

RETRIEVE (LOCAL TYPE) ASCII (Local Pathname) TEST 1

(for. Pathname) Test.pl1 user-ftp Opens local file in ascii. Retr Test.pl1 ---->

<---- 150 File Status is normal, open the data connection server in port U set data connection

Document transfer <---- 226 Turn off data connection, file transfer correct Type Image type i ----> <- 200 Command OK

Store (Local Type) Image (local pathname) file dump

(Pathname)> UDD> CN> FD user-ftp Opens local file in image. stor> udd> cn> fd ---->

<---- 550 Access refusing

Soating Quit ----> Server Close All Connections

The FTP control connection is established via the user process port U and the server port L, which is the default L = 21.

转载请注明原文地址:https://www.9cbs.com/read-126656.html

New Post(0)