The difference between the Port mode and the PASV mode is the mode mode when the data transfer is created in the FTP Transport path. PASV mode is the server-side initialization connection, and the PASV mode is the client initialization connection.
Once the server ends launches two sockets with fixed port numbers, the server controls the SCONTROLSocket port is 21, and the data SDATASOCKET port is specified as 1650.
Main thread: Control port SCONTROLSocket.accept () has been listening to whether the client tries to establish a connection. . . . . . Corresponding csocket = scontrolsocket.accept () This CSocket in the server-side CSocket creates a connection with the client to start the communication with the communication of this CSocket and the client. Communication is a newly opened a sub-communication specific (client's clientsocket) 1. ClientSocket.connect (EP); // EP is SCONTROLSOCKET ---- C2. CSocket [I] = scontrolsocket.accept () ---- s3. ClientSocket.send (... user ~~~ ----- c4.While (true) {csocket [i] .RecEive (~~~ 存 字 string str} judgment Str.StartWith ("") -> User Data stocks in such USER sends 220 test ---- S5.ClientSocket.Receive (.. if the first three strings are started with 220 (., Pass ~~~ ----- c6. 4 Step, judgment str.startwith (") -> pass If the database corresponds to the USER in the database, this pass is the same, send 220 test ---- s7.clientsocket.receive (.. if the first three strings It is 220 to start clientsocket.send (. Pasv ~~~ ----- C8. Step 4, judging Str.StartWith ("") -> PASV PASV is a passive mode, which is the server side receives After the client's PASV command, first CSocket [i] transmission, such as: 150. (. 7, 18) so that the client knows the server to open the data port of 7 * 256 18, while sdatasocket.accept () Waiting, if the customer Go to the connection (the client already knows the 20-port, instantiate a new Socket), there is CSocket [J] = SDataSocket.accept (), so there is two socket communication for a client, this CSOCKET [J] .send (Result, then the server's CSocket [J] loop judgment, if the connection of the SDATASOCKET is disconnected CSocket [i] .send (220 ..., the client receives the result to close the data connection. To this PASV mode end
Initialize 100 Control CSockets, 100 Connection Clients, CDATasocket
As long as a SSocket is bound to a local server endpoint, start listening | | Create a main thread: | | | Loop Execute the following program: | | | The following code block is a critical area | | | SSOCKET has been Listening, get a available CSocket, create a sub-thread on the request connection with CSocket to handle the specific FTP request for a client | | | |