FileZilla FTP Server Source Code Analysis (2)

Source: Internet
Author: User
Tags ftp commands website server ftp client filezilla filezilla ftp ftp protocol

FileZillaFTP Server Source Code Analysis: FileZilla is a free and open-source FTP tool. Including FileZilla Client and FileZilla Server. FileZilla Server only provides windows versions. to upload a local website webpage file to the website Server or download a webpage file from the Server, you only need the FileZilla Client Version. FileZilla FTP Server Source code. Before further analyzing the code, review the FTP protocol, which is the structure of FTP.

The client and server communicate through two connections:

One is to control the connection, that is, to transmit some control commands, the client sends FTP commands, and the server gives a response, such as the USER and PASS commands. In this connection, the FTP server port is the well-known port 21, and the connection is initiated by the client, for example, ftp 192.168.0.1. For a command-line program such as dig, the user uses ftp commands on the user interface, such as ls, get, and cd. These ftp commands are not commands that really interact with the FTP server, these ftp commands also need to be translated by the "USER protocol interpreter" into real ftp protocol commands, such as USER and PASS, in order to interact with the server.

One is data connection, that is, the real file transmission is performed on this connection. The data connection port of the server is 20, and the data connection port of the client is randomly generated. The data connection only exists when the file is transmitted. After the file is transferred, the connection is disconnected. If you need to transfer the file again, a data connection is established again (the client port is random, not necessarily the last one ). There are two data connection modes: Active Mode and passive mode. The difference between the two is who initiates the data connection.

Let's look at a simple ftp.exe process, which uses the Windows ftp.exe program. First, create a connection, then ls to check the file list, run the get command to load a file, and then close quit. The following-d option shows the interaction details. Note that the line starting with --> is the request sent from the ftp client to the FTP server. The line starting with three digits is the server response, rows starting with 220,331, for example:

C: \> ftp-d localhost

Connected to dell.

220-FileZilla Server version 0.9.18 beta

220-written by Tim Kosse (Tim.Kosse@gmx.de)

220 Please visit http://sourceforge.net/projects/filezilla/

User (dell :( none): robert

---> USER robert

331 Password required for robert

Password:

---> PASS test

230 Logged on

Ftp> ls

---> PORT 4,173, 0

200 Port command successful

---> NLST

150 Opening data channel for directory list.

Manual.txt

226 Transfer OK

Ftp: 175 bytes received, 0.00 Seconds 175000.00 Kbytes/sec.

Ftp> get Manual.txt

---> PORT 4,174, 0

200 Port command successful

---> RETR Manual.txt

150 Opening data channel for file transfer.

226 Transfer OK

Ftp: 17319 bytes received, 0.09 Seconds 192.43 Kbytes/sec.

Ftp> quit

---> QUIT

221 goodbye.com

C: \>

At the beginning, the client sent a connection request:

 
 
  1. C :\>Ftp-d localhost // establish a connection
  2.  
  3. Connected to dell. // connection established
  4.  

Then the server sends the welcome message and requires the user name to be entered:

 
 
  1. 220-FileZilla Server version 0.9.18 beta  
  2.  
  3. 220-written by Tim Kosse (Tim.Kosse@gmx.de)  
  4.  
  5. 220 Please visit http://sourceforge.net/projects/filezilla/  
  6.  
  7. User (dell:(none)):  
  8.  

Enter the username robert on the client and press Enter:

---> USER robert // ftp.exe generates the FTP command: USER, which is sent to the server.

The server requires a password:

331 Password required for robert

Password:

Enter the password on the client and press Enter:

---> PASS test // ftp.exe generates the FTP command: PASS, which is sent to the server

The server passes password verification:

230 Logged on

Enter the ls command on the client

Ftp> ls

Ftp.exe generates the FTP command: PORT to tell the Server Client What the random PORT is.

---> PORT 127,0, 4,173, 256 // 127,0, 0 is the IP address, 4*173 + 1197 = is the random PORT number

200 Port command successful // server response PORT command

---> NLST // the client sends the NLST command to list the file list.

150 Opening data channel for directory list. // The server will establish a data connection with port 1197 of the client at Port 20 to transmit data. Note that the ls command results are transmitted in the "Data Connection ".

Manual.txt // only one file exists

226 Transfer OK // FTP server response, Transfer completed

Ftp: 175 bytes received. The transmission result displayed on the 0.00 Seconds 175000.00 Kbytes/sec. // FTP client is displayed.

The customer needs to download the manual.txt file.

Ftp> get Manual.txt

---> PORT 4,174, 0, 256, 174 // notify the Server client of the new random PORT 4*1198 + =

200 Port command successful // server response PORT command

---> RETR Manual.txt // download the Manual.txt file from the vendor Server

150 Opening data channel for file transfer. // The server establishes a data connection with port 1198 of the client at Port 20 to transmit data.

226 Transfer OK // FTP server response, Transfer completed

Ftp: 17319 bytes received. The transmission result displayed on the 0.09 Seconds 192.43 Kbytes/sec. // FTP client is displayed.

Client exited

Ftp> quit

---> QUIT // issue the QUIT command

221 Goodbye // server final response

By carefully reading the entire process, you can find that a user manually input an ftpcommand can be processed by ftp.exe to interact with the FTP Server Multiple times. Such as ls and get commands.

For more information about FTP commands, see the ftp rfc or related documents. However, the main purpose of reading the source code is not to study FTP details, it is to master the High-concurrency network programming technology, so we only look at the above simple FTP interaction to see how this process is implemented in the code.

  1. FileZilla FTP Server Source Code Analysis 1)
  2. FileZilla FTP Server Source Code Analysis 2)
  3. FileZilla FTP Server Source code analysis 4)
  4. FileZilla FTP Server Source Code Analysis 5)

Related Article

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.