SuperSocket Application of FTP source code analysis

Source: Internet
Author: User
Tags ftp commands ftp file ftp file transfer ftp protocol

A Brief introduction

A command-line protocol is a protocol that uses more than one, with the advantage of being simple and easy to extend, while also facilitating parsing and use. FTP,POP,SMTP, such as the use of command-line protocol, which FTP in the early Internet era become the main way of network resources sharing, the importance of the FTP protocol is visible. I think it is because of the advantages of the command line protocol, so the default protocol for SS is it.

A detailed introduction to FTP can be found here: http://www.cnblogs.com/luoxn28/p/5585458.html, or other blog posts. No matter what the post is, the code best understands how it works and how it works.

In addition, FTP also often in the computer software system architecture as a file server post, to provide file upload download service, film

Two FTP server 2.1 functional Requirements

Ftpserver as a server, you should first provide user management functions, file resource management (similar to Windows Explorer), FTP commands and file transfer, protocol encapsulation and other key functions

2.2 User Management

This can be connected to Windows system users can also be pre-defined users and the configuration file or other means of storage, FTP has anonymous and non-anonymous user login authentication, depending on the security and sharing of the FTP service, for anonymous users, the user is shared and open, For non-anonymous users, permissions can be used to control file access and administration.

2.3 Resource Management

File resource management is similar to Windows Explorer, except that the objects managed here are files, so-called file management mainly includes, query, view, create, delete, modify, which query file list links to recursive knowledge.

2.4 FTP command

The SS has encapsulated the command base class, so just follow the commands of the FTP protocol for the corresponding command class definition

2.5 File Transfer

FTP file transfer has the main passive point, the so-called primary passive for the client, the active mode, the user sends the upload or download the file Service command, and in the command parameters sent with the client actively open port told to the server, the server received the information and attempt to establish a connection with the port and transfer file stream, Vice versa. FTP provides the creation and shutdown of file transfer channels.

2.6 Protocol Encapsulation

The FTP command is both string and OK, so SS uses string Explorer to encapsulate the FTP command, and for the server to send and receive messages directly using the related string resource command

Three communication processes

3.1 Landing

Login process: The client will send the pass command, carry the user name password and other authentication information to the server, of course, this is for non-anonymous FTP, in the received parameters of the user authorization authentication, the verification results returned to the client;

3.2 Execute Command

The execution of the command runs through the client service-side session cycle, such as List command, Abort, and so on.

3.3 File Transfer 3.3.1 Active mode

First, the client initiates the file transfer command download, upload, port,stor, command, carry the client active open client disconnects default to 20 port, this disconnect by default within the firewall is not filtered out, the server received the command to send the client to receive the OK command, and attempt to the client address and the development of the connection , set up binary file stream transmission channel, Code view port command and Stor command

3.3.2 Passive Mode

First or the client to the server to initiate the upload or download command requests, the service side open the random port name sent to the client, the client and the server to establish a data transmission channel, open file transfer

DataConnection: Data connection Channel class, which is mainly responsible for the transmission channel maintenance work, providing channel establishment, file transfer, shutdown and other methods

3.3.3 Channel off

The channel is closed for 3 reasons: The session is closed, the transmission is complete, the transmission is abnormal, the channel closed is closed socket, of course, this is in the passive mode by the service side of the port, which also play a role in recycling.

1  Public Virtual voidClose ()2         {3 Stoplistener ();4 5             if(Client! =NULL&&!m_isclosed)6             {7                 Try8                 {9 Client.shutdown (socketshutdown.both);Ten                 } One                 Catch(Exception e) A                 { - M_Session.Logger.Error (e); -                 } the  -                 Try -                 { - client.close (); +                 } -                 Catch(Exception e) +                 { A M_Session.Logger.Error (e); at                 } -                 finally -                 { -Client =NULL; -M_session =NULL; -m_isclosed =true; in OnClose (); -                 } to             } +}
View Code

SuperSocket Application of FTP source code analysis

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.