About the FTP protocol;
FTP command;
FTP return value;
FTP programming structure;
About the FTP protocol:
Regarding the FTP protocol, I want to know about it, so don't explain it. The following is an introduction of RPC959:
The Objectives of ftp Are 1) TO Promote Sharing of Files (Computer
Programs and / or data, 2) TO ENCOURAGE INDIRECT or IMPLICIT (VIA
Programs) User of Remote Computers, 3) To Shield a User from
Variations in file storage systems among hosts, and 4) to transfer
Data Reliably and efficiently. ftp, though usable directly by a User
At a Terminal, Is Designed Mainly for Use by Programs.
FTP command:
Perhaps many people have used FTP commands, but there may be many people and the same mistakes I have made, and the ftp command is missed. I originally hit FTP under Win2000's console, and then entered the FTP prompt, then I used a number of "windows" characteristics, such as "DIR", "CD", see it according to their own idea In the run, I thought I had a ftp command. I am very confident to open the programming tool, write a socket, and then connect to the FTP server. Of course, the server returns the information prompt is successful, I started to send some commands just used, most of the information that can be returned is "500 'xx': command not understandtood". Finally, I sent a Help command, the result of returning made me amazing, most of the commands I have never used it. These are the real ftp commands. On Windows is just an FTP client tool, the command inside is not an FTP command. There are many data on the Internet, and the commands of the FTP client in Windows and the FTP command are mixed together. The true FTP command should refer to the instructions in the RFC959 document (in fact some FTP tools are displayed in cuteftp). The orders that are often used are as follows:
Abor: abort;
CWD directory name: Change the existing directory;
CDUP: Return to the parent directory;
Rein: Reinitialize the server status;
Quit: Exit;
Port: Set the data transfer port;
PASV: Transfer to passive way
TYPE A / I: Mode of transmission;
Mode S / B / C: Transfer mode? ;
Retr file name: Download file;
STOR file name: upload file;
Append appended local files to the server;
RNFR: Modify the original file name (previous file name before modification)
RNTO: Modified file name;
Dele file name: Delete file;
RMD catalog: Delete folder;
MKD directory: New directory;
PWD current working directory;
List: Lists items in this directory;
SYST: View server operating system information;
STAT View the FTP parameter status; the return value of the ftp command:
After each FTP is sent, the FTP server returns a string, including a return code and a string of description information. This return code is mainly used to determine whether the command is successfully implemented. In addition, there is a very important command to return. After sending the PASV, return "227 Entering Passive Mode (127, 0, 0, 1, 4, 18)". This means that there is a port on the server being opened, he will prepare for our subsequent data transfer, but how do we know that the port number is (127, 0, 0, 1, 4, 18) The front four refers to the address of the server, the key is the last two digits, and the last second multiply 256 plus the last bit is our port number, that is, 4 * 256 18. After obtaining the port number, we can use the socket to connect to here. This is ready for our work, because our list of acquisitions, upload, download files must rely on it. Commonly returned as follows:
125 Data Connection Already Open; Transfer Starting.
226 Transfer Complete.
227 Entering Passive Mode (127, 0, 0, 1, 4, 18).
230 User XXXXX Logged IN.
331 Password Required for xxxxx.
425 can't open data connection.
226 Closing Data Connection.
FTP client programming structure:
The FTP command and its response information have been mentioned earlier. In fact, we do FTP client tools just to connect to the FTP server with a Winsocket, and then send commands. In this process, we rely on the mechanism of sending-responding. That is, send an FTP command - receive the returned response information - Analyze this information - Perform the relevant operation - Send the next command. In the general sense, there is a socket to connect the associated port of the FTP server (such as the default 21), which is responsible for the sending and receiving response information of the FTP command. Some operations such as "Enter Directory", "Delete File", rely on this socket to send a command can be completed. However, for the operation of data transmission, it is mainly to display a remote directory list, upload, download file, we have to rely on another socket to complete. Before doing this, the PASV command must be sent. It returns the information starting with 227, and there is six numbers separated by a comma in parentheses. The first four referrally to the server's address, the key is the last two, the countdown The two multiply 256 plus the last number, the result is the port for the FTP server for the next command to perform data transmission. If we get 227 Entering Passive MODE (127, 0, 0, 1, 4, 18), then the port number is 4 * 256 18 = 1042. We use a socket to connect to this port, which we can send a command based on the specific operation (display directory list, upload file stor, download retr). The returned response code is 125, that is, the connection is opened, and the data can be started, and the data can be transmitted or received by the Socket. After completing, the server will return to code 226 Transfer Complete, indicating that the data transfer is complete. It is worth noting that we'd better send multiple commands once, for example, we have to return to the upper directory and display this directory, we have to send CDUP, PASV, LIST, we can't send: CDUP / R / N, PASV / R / N, LIST / R / N. Instead, wait for its response code after sending the CDUP, and then send it later. When the PASV returns, we open another socket to connect to the relevant port. Then send a list, return 125 after starting receiving data, and finally returns 226 indicate completion. It is also the process of uploading and downloading (the size of the file must be obtained before downloading). Reference:
.NET Network Advanced Programming: Tsinghua University Press, Andrew Krowczyk;
RFC959;
VisualBasic.net network programming learning shortcut;