FTP Learning Notes

Source: Internet
Author: User
Tags ftp commands ftp site rfc ftp client ftp protocol

We must distinguish between file transfer and file access, which is provided by FTP, which is provided by an application system such as NFS (Sun's network File system). FTP-supplied files are copies of a file from one system to another.

FTP supports a limited number of file types (ASCII, binary, and so on) and file structure (area byte stream or record).

The IP service type (TOS) used by the FTP control connection is the minimum latency, and the IP service type used by the data connection is the maximum throughput.

The earliest design for FTP was for two different hosts, two of which might run on different operating systems, use different file structures, and use different character sets. Therefore, the FTP protocol regulates a variety of options for controlling file transfer and storage. They have the following four aspects:

FTP clients and servers that are typically implemented by UNIX limit our choices to the following:

1. File type: ASCII or image (also known as binary file type).

2. Format control: Only non-printing is allowed.

3. Structure: Only the file structure is allowed.

4. Transfer mode: Only the flow mode is allowed.

This limits our access to only one or two ways: ASCII or image (binary).


FTP commands and replies are transmitted in NVT ASCII form on the control connection of the client and the server. This requires that the CR, LF pair (that is, each command or each answer) be returned at the end of each line.

FTP command:

These commands are 3 or 4 bytes of uppercase ASCII characters, some with option parameters. There are more than 30 FTP commands sent from the client to the server. The FTP commands that are routed between the type of user interaction and the control connection are sometimes one to the other. But there are also some operations where a user command produces a control connection on multiple FTP commands.

ABOR: Discard previous FTP commands and data transfer

List filename: Lists show files or directories

PASS passworkd: password on the server

Port n1,n2,n3,n4,n5,n6: Client IP address (N1,N2,N3,N4) and port (n5*256 + N6)

QUIT: Log off from the server

RETR FileName: Retrieving (fetching) a file

STOR FileName: Store (put) a file

Syst: Server return system type

Type type: Description file type, a for ASCII code, I for image

User username: username on the server

FTP answer:

The response is a 3-digit number in ASCII format and is followed by an anthology. The reason is that the software system needs to decide how to answer according to the digital code, and the option string is oriented to manual processing.

Each digit in the answer 3-bit code has a different meaning (SMTP uses the same command and answer conventions).

125: Data connection already open, transfer started

200: Ready command

214: Help message (User-facing)

331: User name ready, require password input

425: Cannot Open data connection

452: Wrong Write file

500: Syntax error

501: syntax error (invalid parameter)

502: Non-implemented mode (Mode command) type

Usually each FTP command produces a line of answers. For example, the QUIT command might have the following answer:

221:goodbye

If you need to produce a multiline answer, line 1th contains a hyphen, not a space, after the 3-digit answer code, and the last line contains the same 3-digit answer code, followed by a whitespace. For example, the initial connection to an FTP server can produce the following output:

220-FTP site Powerd by Bigfollcat FTP Server 1.0.

220-welcome to my FTP server

220


Connection management:

The control connection keeps the client-server connection in the whole process, but the data connection can come whenever and whenever necessary. So how do you choose the port number for the data connection, and who is responsible for active open and passive open?

First of all, as we said before, the Universal transport mode (the only transmission in Unix environments) is the flow mode, and the end of the file is marked with a close data connection. This means that a completely new data connection is created for the first file transfer or directory listing. The general process is as follows:

1. The data connection is established under the control of the customer because the customer has issued a request to establish a data connection.

2. Customers typically select a temporary port number on the client host for the data connection that they are on, and the customer releases a passive rip-off from that port.

3. The customer uses the port command to send the port number to the server from the control connection.

4. The server receives the port number on the control connection and publishes an active opening to the port on the client host. Port 20 is always used on the server's data connection side.


Default data port:

On an FTP client that does not issue a port command, if the server attempts to reconnect to the port of the client's previously used data connection, the socket may be prevented from issuing a SYN packet by the TCP implementation of the error being used. When the server still uses port 20 and the client is assumed to be using the previous port number, it will need to wait for the 2MSL timeout to reconnect.

The reason that the Host Requirements RFC recommends using the Port command is to avoid this 2MSL between two successive uses of the data connection, by constantly changing the port number at one end, The problem that we see in the middle of a two-time list server directory waiting for 2MSL is not going to happen.


Text File transfer:

Most clients currently try to determine if they are the same type of system before they are transferred, and once they are identical, they can use binary codes (image file types) to transfer files instead of ASCII code. This can be achieved with two benefits:

1. The sender and receiver pays do not have to look at every byte (great savings)

2. If the machine operating system uses fewer bytes than the 2-byte NVT ASCII sequence to make the end of the line, it transmits fewer bytes (a small savings). For example, when using ASCII code, each new line character (\ n) under UNIX is transferred by the server to the NVT ASCII 2-byte line end sequence (\ r \ n), which is then converted by the customer into its original form for storage.

In addition, if the server file is a compressed file, it must be transferred in binary.

After registering to the server, the client FTP automatically issues the Syst command, and the server responds with its own system type. If the answer is from the string "215 Unix Type:l8", and if the client is running on a UNIX system with 8bit per byte, then the binary mode (image) will be used by all file transfers unless changed by the user.

When we fetch the file hello.c, the client automatically issues the command type I specifies the file types as images. This allows only 38 bytes to be transmitted on the data connection.

The Host Requirements RFC states that an FTP server must support the Syst command.


abnormal termination of a file transfer :

Abnormally terminating files that are passed from the client to the server is easy-as long as the customer stops sending data on the data connection and issues a Abor command to the server on the control connection. and abnormally terminating the reception is much more complicated. This is because the customer wants to tell the server to stop sending the data immediately. The client notifies the server to terminate the send by sending a segment of the message with an emergency pointer and using a Telnet synchronization signal. When the emergency pointer data is received, it reads the next FTP command, looking for Abor or stat, ignoring the embedded telnet command.


Anonymous FTP can use anonymous as the login name, and some anonymous FTP will require clients to reverse resolve to their domain name by IP address.


This article is from the "Collect Tile hing ge" blog, please make sure to keep this source http://ponyjia.blog.51cto.com/917324/1630016

FTP Learning Notes

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.