java implementation FTP protocol: Data Transfer Command Description model and

I mentioned above, once the FTP data transmission after establishing both a control and command channel data transmission channel, both sides can transmit data. In data transmission, FTP protocol also provides three modes, namely, stream mode, block mode and a compressed mode.

Streaming mode actually simple bits to be transmitted in a continuous transmission of unstructured manner with the help of the TCP protocol to the other party, where it is a piece of data, no such information about the organization of the data packet header field exists or . Since the information data to be transmitted is a naked, no structural organization, and therefore the accuracy of the transmission is entirely dependent on the stability of the transmission side and lower layer protocols, in particular depend on the data transfer is completed to close the data channel must be represented.

Compared to the other two modes, the flow pattern is characterized by high efficiency, it is widely used in the implementation of the protocol. At the same time it is simple, and the data will be transmitted to all non-discriminatory, do not control how the structure of data to be transmitted, it will see that all as a byte stream, can be isolated and therefore the implementation complexity of the transmission protocol data structure Impact. Thus high efficiency, simple, the complexity of the data transmission isolating these three characteristics make this transfer mode of FTP achieved mainstream.

The second block mode refers to the data to be transmitted is cut into a plurality of portions of a fixed length, each section header fields such as the use of encapsulation when transmitting such data block transmission between each other to form separate packets. Containing three-byte header field, a length, and other related data blocks, respectively. At the same time there is a special algorithm for a block of data tracking algorithm problem occurs if the data block transfer can be interrupted or restart the transfer process.

The third is the compressed mode. It uses run-length encoding of the transmission data is compressed, and the compressed information as to the header fields are organized, so that the person know how to decompress the data after receiving the thus compressed mode, using header + mode data volume data organized send. Due to the compressed mode of implementation complexity, it is rarely used in the FTP protocol, unless the required amount of data transferred as much as possible under certain conditions to ensure network efficiency and accuracy, the model will be used.

File transfer, and the like ctrl + c ctrl + v, except that the copy operation is within the same computer to transfer data from one directory to another, the file transfer is to transfer data from one computer to another computer. But this difference is created some problems, for example, CR end of the text file on windows + LF expressed, but in the end of the text file using the Mac represent CR, so the text file is copied from a Mac to Windows, File it is easy to go wrong at the end, for the FTP protocol during data transmission to increase the data type of a number of considerations.

First, the FTP protocol dividing the data into four forms to be considered, first, ASCII, which is in the form of text character; the second is EBCDIC, such documents but also the character in the form of character EBCDIC character set from IBM; the third is an image, such documents you can not consider the differences between the different systems; Fourth topical form, is characteristic of such documents, not by a byte length of eight bits, some operating systems have this special characteristic. In practice, we consider only the case of one and three, in the case of an agreement to be responsible for the sign at the end of the file is modified according to the system, the image file Case 2 includes not only an image, such as a zip file there are files in the same format belonging to the image.

After the ASCII file transmission, the sender is added after each character to read single line after the CR + LF, the receiver reads the combination of the two characters know this is the end of a line, and then modify the system according to the current location, if the recipient Mac, then these two characters will be changed to CR. Since the FTP transmission data will be modified, and therefore must not be the "image" provided file transfer type to ASCII type, or else the "image" type of binary file has been modified receiver can not open the file.

Next we look at the data packet format of packet format protocol, especially the control commands. FTP control command has three kinds, the first is an access control command, corresponding to his user login and authentication. The second is the transmission control command, which is used to how the two sides agreed-upon data transmission, for example, set the type of file transferred, set active or passive transfer mode; the third is the FTP service commands that are used to initiate data transmission, modified, or deleted files, and so on. FTP is used when the Transmission Control Protocol Telnet commands, so the command will be sent as plain characters, here we are in a list of commands which are detailed:

Command code command description
USER username Username occur when establishing a connection
PASS password Provide the password when the user logs
ACCT account type Used to set user privileges, usually FTP server directly specify permissions based on user name
CWD Change the current directory Set corresponding to the user's login directory server
CDUP Back to the parent directory The upper layer of the current directory as the data transfer directory
SMNT Mounting structure On the server to mount the new file system to read a particular file
REIN Re-initialized Connect the restart, he will clear the current control parameters, similar to the system reboot
QUIT sign out After the data has been sent when the user logs out

Next we look at control command instructions:

Command code command description
PORT Establish a data transfer port This port will be the client and server to establish a data transmission connection
PASV Passive mode This command allows the client initiates the connection to the server
TYPE file type For setting the file type to be transmitted
STRU File Structure Normally this command is not used
MODE Transfer mode How to set the data transmission, is stream mode, block mode or a compressed mode

Next we look at the description of the service command:

Command code command description
RETR retrieve data Notification server sends data to the client file
BIG storage Client To send a file to the server
STOU The only memory The transfer requires the server to ensure in the current directory under the file can only have a
APP Adding content If the file has the same name as the current transfer files in the directory, then add content transmitted to the end of the same file instead of overwriting files with the same name
TO Allocate memory It asks the server for the file to be sent in advance to allocate storage space
REST Restart Restart the file transfer process, the command is only used in compression or transfer mode block transfer
RNFR Rename the file Will be renamed to specify the file name
RNTO Rename the file Changed its name to the specified file name specified
ABOR Cancel command Notification Server performs a cancel command sent
HIS delete The notification server delete a file
RMD Remove directory The notification server delete the entire directory
MKD Create a directory Notification server creates a new directory
PWD Displays the current directory The notification server to inform the user of the current directory
LIST List Get the current directory of all file names and file information such as modification time
NLST Name list Just get the name of the file in the current directory
SYST system It asks the server to return it in the operating system information
STAT status State requires the server to return the current status of a specified file or a current data transmission
HELP help Asks the server to return information to help clients decide how to use the server
NOOP No action 该命令表示什么操作都不做,服务器会返回”OK"命令从而确保连通正常

后面我们还会再列出一些命令,然后查看数据包结构

更详细的讲解和代码调试演示过程,请点击链接

更多技术信息,包括操作系统,编译器,面试算法,机器学习,人工智能,请关照我的公众号:
这里写图片描述

发布了346 篇原创文章 · 获赞 290 · 访问量 40万+

Guess you like

Origin blog.csdn.net/tyler_download/article/details/104063633