TCP port multiplexing method and device for FTP protocol

By reserving and managing different port sets for the FTP server process, the problem of TCP port allocation failure in high-concurrency transmission is solved, TCP port reuse is realized, and the operating efficiency of the FTP server is improved.

CN115665129BActive Publication Date: 2025-10-31SHANGHAI XIAOYUN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211271236.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-17
Publication Date
2025-10-31
Estimated Expiration
2042-10-17

Smart Images

  • Figure CN115665129B_ABST
    Figure CN115665129B_ABST
Patent Text Reader

Abstract

This invention provides a TCP port multiplexing method and device for the FTP protocol. Each process of the FTP server in this invention pre-reserves and manages a certain number of TCP ports. For different PASV commands of each FTP control connection, the same TCP port is reused; for PASV commands from FTP clients with different IP addresses, the same TCP port is assigned. After the FTP server completes the data connection establishment, it determines the corresponding FTP control connection based on the destination TCP port and the client IP address of the data connection. This achieves TCP port multiplexing, eliminating the problem of insufficient TCP ports causing FTP server service failure during high-concurrency access; for different file transfers within the same FTP control connection, the same port can be reused, improving program running efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a TCP port multiplexing method and device for the FTP protocol. Background Technology

[0002] The FTP protocol is simple and efficient, and is widely used in IT systems. The FTP protocol defines active and passive transfer modes. Passive mode is easier to implement secure access control and is more commonly used in practice. In passive mode, the FTP client first establishes a TCP control connection with the FTP server, and then sends commands and responses over this connection. When uploading or downloading files, the FTP client sends a PASS command to the FTP server. The FTP server allocates a TCP port locally and then sends the port number to the client. The FTP client establishes a TCP connection to this port, which serves as the FTP data connection. File data is transferred over this connection, and the data connection is closed after the transfer is complete.

[0003] FTP servers commonly use a method where the operating system allocates TCP ports. After creating a data connection socket, a `bind` operation is performed, and the operating system randomly allocates an unused TCP port. This TCP port is then sent to the client via the control connection. The FTP server then performs `listen` and `accept` operations on that port to receive connection requests from clients and establish a data connection. Widely used FTP servers in practice, such as vsftpd and Flashftpd, all employ this method.

[0004] The FTP protocol specifies that a separate TCP port needs to be allocated for each file transfer. Traditional methods of randomly binding ports result in excessive TCP port usage. In scenarios where multiple FTP clients are concurrently transferring large numbers of files, the FTP server may fail to allocate TCP ports, leading to data transfer failures. Summary of the Invention

[0005] The purpose of this invention is to provide a TCP port multiplexing method and device for the FTP protocol.

[0006] To address the above problems, this invention provides a TCP port multiplexing method for the FTP protocol, comprising:

[0007] Different sets of port numbers are reserved for different FTP server processes, and the sets of port numbers reserved for any two processes are different;

[0008] Initialize the memory data mapping table of the allocated port numbers and the memory data queue of free reserved port numbers for each process. Among them, the total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by the process. The memory data mapping table of the allocated ports is: <port number, map<client IP address, FTP control connection>>;

[0009] When the FTP server receives a PASV command sent by the FTP client on the FTP control connection of a certain process, it determines whether the PASV command has been allocated a port number.

[0010] If a port has been allocated, send the allocated port number to the FTP client;

[0011] If no port has been allocated, obtain the client IP address corresponding to the PASV command, and determine whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the allocated port numbers of the corresponding process.

[0012] If it is found by traversing the memory data mapping table of the allocated port numbers, insert the record <the FTP client IP address corresponding to the PASV command, the control connection corresponding to the PASV command> into the memory data mapping table among the first port numbers that do not contain the FTP client IP address corresponding to the PASV command found by traversing the memory data mapping table of the allocated port numbers, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client;

[0013] If it is not found by traversing the memory data mapping table of the allocated ports, take out a port number from the head of the memory data queue of the free reserved port numbers of the corresponding process, send the taken-out port number to the FTP client, and insert the taken-out port number and its record <the FTP client IP address corresponding to the PASV command, the FTP control connection corresponding to the PASV command> into the memory data mapping table of the allocated port numbers.

[0014] Further, in the above method, after the FTP server receives a PASV command sent by the FTP client on the FTP control connection of a certain process and determines whether the PASV command has been allocated a port number, it further includes:

[0015] When the FTP control connection is to be closed, delete the record <FTP client IP address, the to-be-closed FTP control connection> under the port number corresponding to the to-be-closed FTP control connection in the memory data mapping table of the allocated port numbers.

[0016] Further, in the above method, when the FTP control connection is closed, after deleting the <FTP client IP address, FTP control connection> record corresponding to the port number in the memory data mapping table of the allocated port numbers, it further includes:

[0017] Determine whether there are other <FTP client IP address, FTP control connection> records corresponding to the port number of the already closed FTP control connection in the memory data mapping table of the allocated port numbers.

[0018] If there is no record, the memory data mapping table of the allocated port numbers deletes the port number corresponding to the already closed FTP control connection, and adds the deleted port number to the tail of the memory data queue of the idle reserved port numbers.

[0019] Further, in the above method, inserting the retrieved port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record into the memory data mapping table of the allocated port numbers includes:

[0020] Establish a data connection between the FTP client and the FTP server based on the port number;

[0021] After the data connection is successfully established, insert the retrieved port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record into the memory data mapping table of the allocated port numbers, and establish the corresponding relationship between the data connection and the FTP control connection.

[0022] According to another aspect of the present invention, there is also provided a TCP port multiplexing device for the FTP protocol, including:

[0023] A reservation unit for reserving different port number sets for the processes of different FTP servers, where any two process reservation port number sets are different;

[0024] An initialization unit for initializing the memory data mapping table of the allocated port numbers and the memory data queue of the idle reserved port numbers for each process, where the total number of allocated ports and idle reserved ports for each process is equal to the total number of ports in the port set reserved for the process, and the memory data mapping table of the allocated ports is: <port number, map<client IP address, FTP control connection>>;

[0025] A judgment unit, configured to, when receiving a PASV command sent by an FTP client on an FTP control connection of a certain process, determine whether the PASV command has been assigned a port number. If a port has been assigned, the assigned port number is sent to the FTP client; if no port has been assigned, the client IP address corresponding to the PASV command is obtained, and it is determined whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing and searching in the memory data mapping table of the assigned port numbers of the corresponding process. If it is found by traversing and searching in the memory data mapping table of the assigned port numbers, in the first port number that does not contain the FTP client IP address corresponding to the PASV command found by traversing and searching in the memory data mapping table of the assigned port numbers, a record of <the FTP client IP address corresponding to the PASV command, the control connection corresponding to the PASV command> is inserted into the memory data mapping table, and the first port number that does not contain the FTP client IP address corresponding to the PASV command is sent to the FTP client; if it is not found by traversing and searching in the memory data mapping table of the assigned ports, a port number is taken from the head of the memory data queue of the idle reserved port numbers of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its record of <the FTP client IP address corresponding to the PASV command, the FTP control connection corresponding to the PASV command> are inserted into the memory data mapping table of the assigned port numbers.

[0026] Further, in the above device, a recycling unit is further included, configured to, when the FTP control connection is to be closed, delete the record of <FTP client IP address, the to-be-closed FTP control connection> under the port number corresponding to the to-be-closed FTP control connection in the memory data mapping table of the assigned port numbers.

[0027] Further, in the above device, the recycling unit is further configured to determine whether there are other records of <FTP client IP address, FTP control connection> under the port number corresponding to the already-closed FTP control connection in the memory data mapping table of the assigned port numbers. If there are no records, the port number corresponding to the already-closed FTP control connection is deleted from the memory data mapping table of the assigned port numbers, and the deleted port number is added to the tail of the memory data queue of the idle reserved port numbers.

[0028] Further, in the above device, the judgment unit is further configured to establish a data connection between the FTP client and the FTP server based on the port number; after the data connection is successfully established, the taken port number and its record of <the FTP client IP address corresponding to the PASV command, the FTP control connection corresponding to the PASV command> are inserted into the memory data mapping table of the assigned port numbers, and a corresponding relationship between the data connection and the FTP control connection is established.

[0029] According to another aspect of the present invention, a computer-readable storage medium is also provided, having stored thereon computer-executable instructions, wherein when executed by a processor, the computer-executable instructions cause the processor to:

[0030] Different sets of port numbers are reserved for different FTP server processes, and the sets of port numbers reserved for any two processes are different;

[0031] Initialize the memory data mapping table of allocated port numbers and the memory data queue of free reserved port numbers for each process. The total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by that process. The memory data mapping table of allocated ports is: <port number, map<client IP address, FTP control connection>>.

[0032] When a PASV command is received from an FTP client on an FTP control connection of a certain process, it is determined whether the PASV command has been assigned a port number.

[0033] If a port has already been assigned, the assigned port number will be sent to the FTP client.

[0034] If no port has been assigned, the client IP address corresponding to the PASV command is obtained, and it is determined whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the assigned port numbers of the corresponding process.

[0035] If the port number is found in the memory data mapping table of the allocated port numbers, then in the first port number found in the memory data mapping table that does not contain the FTP client IP address corresponding to the PASV command, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client.

[0036] If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

[0037] According to another aspect of the present invention, a calculator device is also provided, comprising:

[0038] Processor; and

[0039] A memory configured to store computer-executable instructions, which, when executed, cause the processor to:

[0040] Different sets of port numbers are reserved for different FTP server processes, and the sets of port numbers reserved for any two processes are different;

[0041] Initialize the memory data mapping table of allocated port numbers and the memory data queue of free reserved port numbers for each process. The total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by that process. The memory data mapping table of allocated ports is: <port number, map<client IP address, FTP control connection>>.

[0042] When a PASV command is received from an FTP client on an FTP control connection of a certain process, it is determined whether the PASV command has been assigned a port number.

[0043] If a port has already been assigned, the assigned port number will be sent to the FTP client.

[0044] If no port has been assigned, the client IP address corresponding to the PASV command is obtained, and it is determined whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the assigned port numbers of the corresponding process.

[0045] If the port number is found in the memory data mapping table of the allocated port numbers, then in the first port number found in the memory data mapping table that does not contain the FTP client IP address corresponding to the PASV command, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client.

[0046] If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

[0047] Compared to existing technologies, the FTP server of this invention pre-reserves and manages a certain number of TCP ports for each process. For different PASV commands within each FTP control connection, the same TCP port is reused; for PASV commands from FTP clients with different IP addresses, the same TCP port is assigned. After the FTP server establishes a data connection, it determines the corresponding FTP control connection based on the destination TCP port and the client IP address of the data connection. This achieves TCP port reuse, eliminating the problem of insufficient TCP ports causing FTP server service failure during high-concurrency access; for different file transfers within the same FTP control connection, the same port can be reused, improving program efficiency. Attached Figure Description

[0048] Figure 1 This is a network topology diagram of an FTP client and server according to an embodiment of the present invention;

[0049] Figure 2 This is a diagram illustrating the interaction between a passive mode FTP client and server according to an embodiment of the present invention.

[0050] Figure 3 This is a flowchart of a passive mode FTP server port allocation according to an embodiment of the present invention;

[0051] Figure 4 This is a flowchart of a passive mode FTP server port recycling process according to an embodiment of the present invention. Detailed Implementation

[0052] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0053] like Figure 1 As shown, this invention provides a TCP port multiplexing method for the FTP protocol, comprising:

[0054] Step S1: Reserve different sets of port numbers for different FTP server processes, wherein any two processes shall reserve different sets of port numbers.

[0055] Here, the FTP server and client network topology involved in the embodiments of the present invention is as follows: Figure 1 As shown, multiple FTP clients access the FTP server via the FTP protocol.

[0056] FTP clients can communicate with FTP servers using passive mode. When the FTP server starts, a certain number of ports can be reserved and managed in advance. Specifically, when the FTP server starts, a certain number of TCP port sets R can be reserved and loaded into memory for unified management. In a multi-process FTP environment, the reserved port sets of any two processes are different. Process 1 reserves port set R1, process 2 reserves port set R2, ..., process n reserves port set Rn, satisfying the following relationship: R1∪R2...∪Rn=R;

[0057] When an FTP server uses a multi-process mode, each process can reserve a different port number.

[0058] One process can correspond to multiple FTP control connections, while one FTP control connection can only correspond to one process.

[0059] Only one FTP control connection of one process can be used on the same port at the same time; multiple FTP control connections of the same process can reuse the same port at different times.

[0060] One FTP control connection can only correspond to one FTP client;

[0061] Step S2: Initialize the memory data mapping table of allocated port numbers and the memory data queue of free reserved port numbers for each process. The total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by that process. The memory data mapping table of allocated ports is <port number, map<client IP address, FTP control connection>>, and the memory data queue of free reserved ports is <reserved port number 1, reserved port number 2, ..., reserved port number n>.

[0062] Here, the FTP server can use two data structures to manage the TCP port:

[0063] (1) Memory data mapping table of assigned port numbers: map<port number, map<client IP address, FTP control connection>>AssignPortMap;

[0064] (2) Memory data queue for idle reserved port numbers: queue<reserved port1, reserved port2…reserved portn>ReservePortQueue;

[0065] Step S3: When the FTP server receives a PASV command from an FTP client on an FTP control connection of a certain process, it determines whether the PASV command has been assigned a port number.

[0066] Here, the FTP client accesses resources on the FTP server via the FTP protocol. In passive mode, the FTP client sends the PASV command to the FTP server. The FTP server allocates a TCP port and sends the allocated port to the FTP client. The FTP client establishes a data connection to the server's TCP port, and subsequently uses this data connection to transfer data. The interaction is as follows: Figure 2 As shown;

[0067] Step S4: If a port has already been assigned, send the assigned port number to the FTP client.

[0068] Step S5: If no port has been allocated, obtain the client IP address corresponding to the PASV command, and determine whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the allocated port numbers of the corresponding process.

[0069] Step S6: If the port number is found in the memory data mapping table of allocated port numbers, then in the first port number found in the memory data mapping table of allocated port numbers that does not contain the FTP client IP address corresponding to the PASV command, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client.

[0070] Here, different FTP client IP addresses can reuse the same port, but the same FTP client IP address cannot reuse the same port, in order to avoid confusion of FTP control connections;

[0071] Step S7: If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

[0072] Here, as Figure 3 As shown, when an FTP server processes the PASV command of the FTP protocol, port allocation includes the following steps:

[0073] a) Determine if the FTP control connection has been assigned a port. If it has, use the assigned port directly.

[0074] b) If the FTP control connection has not been assigned a port, traverse the memory data mapping table of the assigned ports to find the first port that does not contain the client IP address, that is, the client IP address is not in the mapping table map<FTP client IP address, FTP control connection>. If such a port is found, add the client address to the assigned address entry, that is, insert the record <FTP client IP address, FTP control connection> into the mapping table corresponding to the port in the memory data mapping table AssignPortMap of the assigned ports.

[0075] c) If there is no port in the memory data mapping table AssignPortMap of the assigned ports that meets the conditions, that is, there is no port in the assigned ports that meets the conditions, pop a reserved port number from the head of the memory data queue ReservePortQueue of the idle reserved port numbers for assignment. At the same time, create a data connection, and after successfully performing the bind and listen operations, add the port number to the AssignPortMap data structure.

[0076] As Figure 2 shown, after the FTP server sends the assigned destination port number to the FTP client, the FTP server calls accept to wait for the FTP client to establish a data connection; after the FTP server receives the data connection request, it checks the FTP client IP address of the data connection, and searches for the corresponding FTP control connection from the memory data mapping table of the assigned ports according to the destination port number and the FTP client IP address, and establishes the correspondence between the FTP control connection and the FTP data connection; at this point, the data connection between the FTP server and the FTP client is successfully established, and data communication can be carried out.

[0077] Each process of the FTP server of the present invention pre-reserves a certain number of TCP ports and manages them. For different PASV commands of each FTP control connection, the same TCP port is reused; for PASV commands of FTP clients from different IP addresses, the same TCP port is assigned for use. After the FTP server completes the establishment of the data connection, according to the destination TCP port and the client IP address of the data connection, it is determined which FTP control connection the data connection finds. This realizes the reuse of TCP ports, eliminates the problem that the FTP server cannot provide services due to insufficient TCP ports during high-concurrency access; for different file transfers of the same FTP control connection, the same port can be reused, improving the program operation efficiency.

[0078] The present invention can improve the TCP port usage efficiency of the FTP server and solve problems such as port binding failure and the need to retry multiple times faced by the traditional TCP port allocation method.

[0079] In an embodiment of the TCP port multiplexing method for the FTP protocol according to the present invention, in step S3, after the FTP server determines whether the PASV command has been assigned a port number when receiving the PASV command sent by the FTP client on the FTP control connection of a certain process, it further includes:

[0080] Step S8, when the FTP control connection is to be closed, delete the <FTP client IP address, FTP control connection to be closed> record under the port number corresponding to the FTP control connection to be closed in the memory data mapping table with the assigned port number.

[0081] In an embodiment of the TCP port multiplexing method for the FTP protocol according to the present invention, in step S8, after deleting the <FTP client IP address, FTP control connection> record under the corresponding port number in the memory data mapping table with the assigned port number when the FTP control connection is closed, it further includes:

[0082] Step S9, determine whether there are other <FTP client IP address, FTP control connection> records under the port number corresponding to the already closed FTP control connection in the memory data mapping table with the assigned port number.

[0083] If there is no record, delete the port number corresponding to the already closed FTP control connection in the memory data mapping table with the assigned port number, and add the deleted port number to the tail of the memory data queue of the idle reserved port numbers.

[0084] Here, as Figure 4 shown, when the FTP control connection is closed, TCP port recycling needs to be performed. The port recycling includes the following steps:

[0085] a) In the AssignPortMap set, according to the port number retrieved from the control connection, delete the corresponding client IP address record in <port number, <client IP address, FTP control connection>>, such as the <FTP client IP address, FTP control connection to be closed> record.

[0086] b) For this TCP port number, if there is still a <FTP client IP address, FTP control connection> record, it indicates that there is another control connection using this port. Then, only one <FTP client IP address, FTP control connection> record in the AssignPortMap is deleted in this recycling, and no other recycling actions are taken.

[0087] c) For this TCP port, if all <FTP client IP address, FTP control connection> records under this port number have been deleted, after deleting the port record in AssignPortMap, add this port to the end of ReservePortQueue so that it can be used again in the next allocation.

[0088] In an embodiment of the TCP port multiplexing method for the FTP protocol according to the present invention, in step S7, inserting the retrieved port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record into the in-memory data mapping table of the allocated port numbers includes:

[0089] Step S71, establish a data connection between the FTP client and the FTP server based on the port number. After the data connection is successfully established, insert the retrieved port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record into the in-memory data mapping table of the allocated port numbers, and establish the corresponding relationship between the data connection and the FTP control connection.

[0090] According to another aspect of the present invention, there is also provided a computer-readable storage medium, on which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the processor:

[0091] Reserve different sets of port numbers for the processes of different FTP servers, where any two processes' reserved port number sets are different;

[0092] Initialize the in-memory data mapping table of the allocated port numbers and the in-memory data queue of the idle reserved port numbers for each process. The total number of allocated ports and idle reserved ports for each process is equal to the total number of ports in the port set reserved for the process. The in-memory data mapping table of the allocated ports is: <port number, map<client IP address, FTP control connection>>;

[0093] When receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, determine whether the PASV command has been allocated a port number.

[0094] If a port has been allocated, send the allocated port number to the FTP client;

[0095] If no port has been allocated, obtain the client IP address corresponding to the PASV command, and determine whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the in-memory data mapping table of the allocated port numbers of the corresponding process.

[0096] If the port number is found in the memory data mapping table of the allocated port numbers, then in the first port number found in the memory data mapping table that does not contain the FTP client IP address corresponding to the PASV command, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client.

[0097] If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

[0098] According to another aspect of the present invention, a calculator device is also provided, comprising:

[0099] Processor; and

[0100] A memory configured to store computer-executable instructions, which, when executed, cause the processor to:

[0101] Different sets of port numbers are reserved for different FTP server processes, and the sets of port numbers reserved for any two processes are different;

[0102] Initialize the memory data mapping table of allocated port numbers and the memory data queue of free reserved port numbers for each process. The total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by that process. The memory data mapping table of allocated ports is: <port number, map<client IP address, FTP control connection>>.

[0103] When a PASV command is received from an FTP client on an FTP control connection of a certain process, it is determined whether the PASV command has been assigned a port number.

[0104] If a port has already been assigned, the assigned port number will be sent to the FTP client.

[0105] If no port has been assigned, the client IP address corresponding to the PASV command is obtained, and it is determined whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the assigned port numbers of the corresponding process.

[0106] If the port number is found in the memory data mapping table of the allocated port numbers, then in the first port number found in the memory data mapping table that does not contain the FTP client IP address corresponding to the PASV command, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client.

[0107] If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

[0108] Compared to existing technologies, the FTP server of this invention pre-reserves and manages a certain number of TCP ports for each process. For different PASV commands within each FTP control connection, the same TCP port is reused; for PASV commands from FTP clients with different IP addresses, the same TCP port is assigned. After the FTP server establishes a data connection, it determines the corresponding FTP control connection based on the destination TCP port and the client IP address of the data connection. This achieves TCP port reuse, eliminating the problem of insufficient TCP ports causing FTP server service failure during high-concurrency access; for different file transfers within the same FTP control connection, the same port can be reused, improving program efficiency.

[0109] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0110] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0111] Obviously, those skilled in the art can make various modifications and variations to the invention without departing from the spirit and scope of the invention. Therefore, if these modifications and variations fall within the scope of the claims of the invention and their equivalents, the invention is also intended to include these modifications and variations.

Claims

1. A TCP port multiplexing method for the FTP protocol, characterized in that, Include: Reserve different sets of port numbers for processes of different FTP servers, where any two processes' reserved port number sets are different; Initialize the memory data mapping table of the allocated port numbers and the memory data queue of the idle reserved port numbers for each process. Among them, the total number of the allocated ports and the idle reserved ports for each process is equal to the total number of ports in the port set reserved by the process. The memory data mapping table of the allocated ports is: <port number, map<client IP address, FTP control connection>>; When the FTP server receives a PASV command sent by the FTP client on the FTP control connection of a certain process, determine whether the PASV command has been allocated a port number. If a port has been allocated, send the allocated port number to the FTP client; If no port has been allocated, obtain the client IP address corresponding to the PASV command, and determine whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the allocated port numbers of the corresponding process. If it is found by traversing the memory data mapping table of the allocated port numbers, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table among the first port numbers that do not contain the FTP client IP address corresponding to the PASV command found by traversing the memory data mapping table of the allocated port numbers, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client; If it is not found by traversing the memory data mapping table of the allocated ports, take out a port number from the head of the memory data queue of the idle reserved port numbers of the corresponding process, send the taken-out port number to the FTP client, and insert the taken-out port number and its record <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> into the memory data mapping table of the allocated port numbers.

2. The TCP port multiplexing method for the FTP protocol as described in claim 1, characterized in that, After the FTP server receives a PASV command sent by the FTP client on the FTP control connection of a certain process and determines whether the PASV command has been allocated a port number, it further includes: When the FTP control connection is to be closed, delete the record <FTP client IP address, FTP control connection to be closed> under the port number corresponding to the FTP control connection to be closed in the memory data mapping table of the allocated port numbers.

3. The TCP port multiplexing method for the FTP protocol as described in claim 2, characterized in that, After deleting the record <FTP client IP address, FTP control connection> under the corresponding port number in the memory data mapping table of the allocated port numbers when the FTP control connection is closed, it further includes: Determine whether there are other records <FTP client IP address, FTP control connection> under the port number corresponding to the FTP control connection that has been closed in the memory data mapping table of the allocated port numbers. If no record is found, the memory data mapping table of the allocated port number will delete the port number corresponding to the closed FTP control connection, and the deleted port number will be added to the tail of the memory data queue of the free reserved port number.

4. The TCP port multiplexing method for the FTP protocol as described in claim 1, characterized in that, The extracted port number and its corresponding FTP client IP address and FTP control connection (corresponding to the PASV command) record are inserted into the memory data mapping table of the allocated port number, including: A data connection is established between the FTP client and the FTP server based on the port number; After the data connection is successfully established, the extracted port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number, and the correspondence between the data connection and the FTP control connection is established.

5. A TCP port multiplexing device for the FTP protocol, characterized in that, include: The reserved unit is used to reserve different sets of port numbers for different FTP server processes, wherein any two processes will have different sets of reserved port numbers; An initialization unit is used to initialize the memory data mapping table of allocated port numbers and the memory data queue of free reserved port numbers for each process. The total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by that process. The memory data mapping table of allocated ports is: <port number, map<client IP address, FTP control connection>>. The judgment unit is used to, upon receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, determine whether a port number has been assigned to the PASV command. If a port number has been assigned, the assigned port number is sent to the FTP client. If no port number has been assigned, the unit obtains the client IP address corresponding to the PASV command and determines whether the first port number not containing the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the assigned port numbers of the corresponding process. If such a port number is found, the unit then retrieves the first port number not containing the FTP client IP address corresponding to the PASV command from the memory data mapping table of the assigned port numbers. In the port number of the address, insert the record <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client; if it is not found in the memory data mapping table of allocated ports, take a port number from the head of the memory data queue of the free reserved port number of the corresponding process, send the taken port number to the FTP client, and insert the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record into the memory data mapping table of allocated port numbers.

6. The TCP port multiplexing device for the FTP protocol as described in claim 5, characterized in that, It further includes a recycling unit, which is used to delete the <FTP client IP address, to-be-closed FTP control connection> record under the port number corresponding to the to-be-closed FTP control connection in the memory data mapping table with allocated port numbers when the FTP control connection is to be closed.

7. The TCP port multiplexing device for the FTP protocol as described in claim 6, characterized in that, The recycling unit is further used to determine whether there are other <FTP client IP addresses, FTP control connections> records under the port number corresponding to the already-closed FTP control connection in the memory data mapping table with allocated port numbers. If there is no record, the memory data mapping table with allocated port numbers deletes the port number corresponding to the already-closed FTP control connection, and adds the deleted port number to the tail of the memory data queue of free reserved port numbers.

8. The TCP port multiplexing device for the FTP protocol as described in claim 5, characterized in that, The judging unit is further used to establish a data connection between the FTP client and the FTP server based on the port number; after the data connection is successfully established, insert the retrieved port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record into the memory data mapping table with allocated port numbers, and establish the corresponding relationship between the data connection and the FTP control connection.

9. A computer-readable storage medium having stored thereon computer-executable instructions, wherein, When the computer-executable instructions are executed by the processor, the processor is caused to: Reserve different sets of port numbers for processes of different FTP servers, where any two sets of reserved port numbers are different; Initialize the memory data mapping table with allocated port numbers and the memory data queue of free reserved port numbers for each process. Among them, the total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the set of ports reserved for the process. The memory data mapping table of allocated ports is: <port number, map<client IP address, FTP control connection>>; When receiving a PASV command sent by an FTP client on an FTP control connection of a certain process, judge whether the PASV command has been allocated a port number, If a port has been allocated, send the allocated port number to the FTP client; If no port has been allocated, obtain the client IP address corresponding to the PASV command, and judge whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table with allocated port numbers of the corresponding process, If it is found by traversing the memory data mapping table with allocated port numbers, insert the <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> record into the memory data mapping table in the first port number that does not contain the FTP client IP address corresponding to the PASV command found by traversing the memory data mapping table with allocated port numbers, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client; If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

10. A calculator device, wherein, include: processor; as well as A memory configured to store computer-executable instructions, which, when executed, cause the processor to: Different sets of port numbers are reserved for different FTP server processes, and the sets of port numbers reserved for any two processes are different; Initialize the memory data mapping table of allocated port numbers and the memory data queue of free reserved port numbers for each process. The total number of allocated ports and free reserved ports for each process is equal to the total number of ports in the port set reserved by that process. The memory data mapping table of allocated ports is: <port number, map<client IP address, FTP control connection>>. When a PASV command is received from an FTP client on an FTP control connection of a certain process, it is determined whether the PASV command has been assigned a port number. If a port has already been assigned, the assigned port number will be sent to the FTP client. If no port has been assigned, the client IP address corresponding to the PASV command is obtained, and it is determined whether the first port number that does not contain the FTP client IP address corresponding to the PASV command is found by traversing the memory data mapping table of the assigned port numbers of the corresponding process. If the port number is found in the memory data mapping table of the allocated port numbers, then in the first port number found in the memory data mapping table that does not contain the FTP client IP address corresponding to the PASV command, insert the record <FTP client IP address corresponding to the PASV command, control connection corresponding to the PASV command> into the memory data mapping table, and send the first port number that does not contain the FTP client IP address corresponding to the PASV command to the FTP client. If the port number is not found in the memory data mapping table of the allocated ports, a port number is taken from the head of the memory data queue of the free reserved port number of the corresponding process, the taken port number is sent to the FTP client, and the taken port number and its <FTP client IP address corresponding to the PASV command, FTP control connection corresponding to the PASV command> record are inserted into the memory data mapping table of the allocated port number.

Citation Information

Patent Citations

  • Systems and methods for server initiated connection management in a multi-core system

    CN103155496A

  • Method and device for realizing fixed communication port for file transfer protocol data link

    CN106899635A