CN115665129A - TCP port multiplexing method and equipment for FTP - Google Patents

TCP port multiplexing method and equipment for FTP Download PDF

Info

Publication number
CN115665129A
CN115665129A CN202211271236.XA CN202211271236A CN115665129A CN 115665129 A CN115665129 A CN 115665129A CN 202211271236 A CN202211271236 A CN 202211271236A CN 115665129 A CN115665129 A CN 115665129A
Authority
CN
China
Prior art keywords
port number
ftp
allocated
port
memory data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211271236.XA
Other languages
Chinese (zh)
Inventor
王飞平
石连星
程妹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Xiao Yun Info Tech Co ltd
Original Assignee
Shanghai Xiao Yun Info Tech Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Xiao Yun Info Tech Co ltd filed Critical Shanghai Xiao Yun Info Tech Co ltd
Priority to CN202211271236.XA priority Critical patent/CN115665129A/en
Publication of CN115665129A publication Critical patent/CN115665129A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention provides a TCP port multiplexing method and equipment facing to an FTP protocol. For different PASV commands connected with each FTP control, the same TCP port is repeatedly used; the same TCP port is allocated for FTP client PASV commands from different IP addresses. After the FTP server completes the establishment of the data connection, the data connection is determined to find the corresponding FTP control connection according to the destination TCP port and the IP address of the client of the data connection. The multiplexing of the TCP ports is realized, and the problem that the FTP server cannot provide service due to insufficient TCP ports during high concurrent access is solved; for different file transmission connected with the same FTP control, the same port can be multiplexed, and the program operation efficiency is improved.

Description

TCP port multiplexing method and equipment for FTP
Technical Field
The invention relates to a TCP port multiplexing method and equipment for an FTP protocol.
Background
The FTP protocol has the advantages of simplicity and high efficiency, and is widely applied to IT systems. The FTP protocol defines active and passive transfer modes. Among them, the passive mode is easier to implement secure access control, and is more applied 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 the control connection. When uploading or downloading files, the FTP client sends PASS commands to the FTP server, and the FTP server locally allocates a TCP port and then sends the port to the client. The FTP client establishes TCP connection to the port as data connection of FTP, transmits file data on the connection, and closes the data connection after the transmission is finished.
FTP servers commonly use a method of allocating TCP ports by an operating system. After creating the data connection socket, executing bind operation, randomly allocating an unused TCP port by the operating system, sending the TCP port to the client through the control connection, and then executing listen and accept operation on the port by the FTP server to receive the connection request of the client and establish the data connection. FTP servers such as vsftpd, flashftp and the like widely applied in practice use the method.
The FTP protocol specifies that one TCP port needs to be allocated each time a file is transferred. The traditional method of randomly binding ports results in the use of a large number of TCP ports. Under the scene that a plurality of FTP clients transmit a large number of files at high concurrency, TCP port allocation failure of the FTP server can occur, and data transmission failure is caused.
Disclosure of Invention
The invention aims to provide a TCP port multiplexing method and equipment for an FTP protocol.
In order to solve the above problem, the present invention provides a TCP port multiplexing method facing to the FTP protocol, which includes:
reserving different port number sets for processes of different FTP servers, wherein any two process reserved port number sets are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, the FTP server judges whether the PASV command allocates a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
Further, in the above method, after the FTP server receives a PASV command sent by the FTP client over an FTP control connection of a process, and determines whether the PASV command has already been assigned a port number, the method further includes:
and when the FTP control connection is to be closed, deleting < the IP address of the FTP client under the port number corresponding to the FTP control connection to be closed and the record of the FTP control connection to be closed in a memory data mapping table of the allocated port number.
Further, in the above method, when the FTP control connection is closed, after deleting the < FTP client IP address and FTP control connection > record in the memory data mapping table of the allocated port number under the corresponding port number, the method further includes:
judging whether other < FTP client IP address, FTP control connection > records exist under the port number corresponding to the closed FTP control connection in the memory data mapping table of the allocated port number,
and if no record exists, deleting the port number corresponding to the closed FTP control connection by the memory data mapping table with the allocated port number, and adding the deleted port number to the tail part of the memory data queue of the idle reserved port number.
Further, in the above method, inserting a port number taken out and its < FTP client IP address corresponding to the PASV command, an FTP control connection > record corresponding to the PASV command into a memory data mapping table of the allocated port number includes:
establishing data connection between the FTP client and the FTP server based on the port number;
and after the data connection is successfully established, inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command, wherein the FTP control connection > record corresponding to the PASV command is inserted into the memory data mapping table of the allocated port number, and establishing the corresponding relation between the data connection and the FTP control connection.
According to another aspect of the present invention, there is also provided a TCP port multiplexing device facing an FTP protocol, including:
the reservation unit is used for reserving different port number sets for the processes of different FTP servers, wherein any two process reserved port number sets are different;
an initialization unit, configured to initialize a memory data mapping table of an allocated port number and a memory data queue of an idle reserved port number of each process, where a total number of allocated ports and idle reserved ports of each process is equal to a total number of ports in a port set reserved by the process, and a memory data mapping table of allocated ports is: port number, map < client IP address, FTP control connection > >;
the system comprises a judging unit, a processing unit and a processing unit, wherein the judging unit is used for judging whether a port number is already allocated to a PASV command when the PASV command sent by an FTP client on FTP control connection of a certain process is received, and sending the allocated port number to the FTP client if the port is already allocated; if no port is allocated, acquiring a client IP address corresponding to the PASV command, judging whether a port number which does not contain the FTP client IP address corresponding to the PASV command is searched in a traversal mode from a memory data mapping table of an allocated port number of a corresponding process, if the port number is searched in a traversal mode from the memory data mapping table of the allocated port number, inserting < the FTP client IP address corresponding to the PASV command in a port number which is searched in a traversal mode from the memory data mapping table of the allocated port number and does not contain the FTP client IP address corresponding to the PASV command, recording a control connection > corresponding to the PASV command into the memory data mapping table, and sending the first port number which does not contain the FTP client IP address corresponding to the PASV command to the FTP client; and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
Further, in the above device, a recovery unit is further included, configured to delete an < FTP client IP address and an FTP control connection > record to be closed under a port number corresponding to the FTP control connection to be closed from a memory data mapping table to which the port number has been allocated when the FTP control connection is to be closed.
Further, in the above device, the recovery unit is further configured to determine whether there are other < FTP client IP address, FTP control connection > records in the memory data mapping table to which the port number has been allocated under the port number corresponding to the closed FTP control connection, and if there is no record, delete the port number corresponding to the closed FTP control connection in the memory data mapping table to which the port number has been allocated, and add the deleted port number to the tail of the memory data queue of the idle reserved port number.
Further, in the above device, the determining unit is further configured to establish a data connection between the FTP client and the FTP server based on the port number; and after the data connection is successfully established, inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command, wherein the FTP control connection > record corresponding to the PASV command is inserted into the memory data mapping table of the allocated port number, and establishing the corresponding relation between the data connection and the FTP control connection.
According to another aspect of the present invention, there is also provided a computer-readable storage medium having stored thereon computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, cause the processor to:
reserving different port number sets for processes of different FTP servers, wherein any two process reserved port number sets are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, judging whether the PASV command has allocated a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
According to another aspect of the present invention, there is also provided a calculator device, including:
a processor; and
a memory arranged to store computer executable instructions that, when executed, cause the processor to:
reserving different port number sets for processes of different FTP servers, wherein the reserved port number sets of any two processes are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, judging whether the PASV command has allocated a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
Compared with the prior art, each process of the FTP server reserves a certain number of TCP ports in advance and manages the TCP ports. For different PASV commands connected with each FTP control, the same TCP port is repeatedly used; the same TCP port is allocated for FTP client PASV commands from different IP addresses. After the FTP server completes the establishment of the data connection, the data connection is determined to find the corresponding FTP control connection according to the destination TCP port and the IP address of the client of the data connection. The multiplexing of the TCP ports is realized, and the problem that the FTP server cannot provide service due to insufficient TCP ports during high concurrent access is solved; and for different file transmissions connected with the same FTP control, the same port can be multiplexed, and the program operation efficiency is improved.
Drawings
FIG. 1 is a network topology diagram of FTP client and server in accordance with an embodiment of the present invention;
FIG. 2 is a diagram of passive mode FTP client and server interaction in accordance with an embodiment of the present invention;
FIG. 3 is a flow chart of port assignment for a passive mode FTP server according to one embodiment of the present invention;
fig. 4 is a flowchart illustrating port reclamation for a passive-mode FTP server according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
As shown in fig. 1, the present invention provides a TCP port multiplexing method facing to the FTP protocol, including:
step S1, reserving different port number sets for processes of different FTP servers, wherein any two process reserved port number sets are different;
the network topology of the FTP server and the client according to the embodiment of the present invention is shown in fig. 1. And a plurality of FTP clients access the FTP server through the FTP protocol.
The FTP client can communicate with the FTP server by using a passive mode; when the FTP server is started, a certain number of ports can be reserved in advance and managed; specifically, when the FTP server is started, a certain number of TCP port sets R may be reserved, and the reserved ports are loaded into the memory for unified management; any two process reserved port sets of the FTP multiple processes are different, a process 1 reserved port set R1, a process 2 reserved port set R2, \ 8230, and a process n reserved port set Rn meet the following relations: r1 ═ R2. -. U τ Rn = R;
Figure BDA0003894324100000081
when the FTP server can adopt a multi-process mode, each process reserves different port numbers;
one process can correspond to a plurality of FTP control connections, and one FTP control connection can only correspond to one process;
the same port can only be provided for one FTP control connection of one process at the same time; multiple FTP control connections in the same process can multiplex the same port at different times;
one FTP control connection can only correspond to one FTP client;
s2, initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, the memory data mapping table of the allocated port is the port number, map is the client IP address, FTP control connection > >, and the memory data queue of the idle reserved port is the reserved port number 1, the reserved port number 2, \8230, and the reserved port number n >;
here, the FTP server can manage TCP ports using 2 data structures:
(1) Memory data mapping table with assigned port number: map < port number, map < client IP address, FTP control connection > > assign portmap;
(2) The memory data queue of the idle reserved port number: queue < reserved port 1, reserved port 2 \8230, reserved port n > ReservePortQueue;
step S3, the FTP server judges whether the PASV command has allocated a port number when receiving the PASV command sent by the FTP client on the FTP control connection of a certain process,
here, the FTP client accesses the resources on the FTP server through the FTP protocol, in the passive mode, the FTP client sends a PASV command to the FTP server, the FTP server allocates a TCP port, sends the allocated port to the FTP client, the FTP client establishes a data connection to the TCP port of the server, subsequently transmits data using the data connection, and the interaction is as shown in fig. 2;
s4, if the port is allocated, sending the allocated port number to the FTP client;
step S5, if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the first port number which does not contain the FTP client IP address corresponding to the PASV command from the memory data mapping table of the allocated port number of the corresponding process in a traversing way,
step S6, if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the FTP client IP address corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the FTP client IP address corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the FTP client IP address corresponding to the PASV command to the FTP client;
different FTP client IP addresses can multiplex the same port, and the same FTP client IP address can not multiplex the same port, so as to avoid FTP control connection confusion;
and S7, if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number of the corresponding process, sending the taken out port number to the FTP client, and inserting the taken out port number and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number.
Here, as shown in fig. 3, when the FTP server processes the PASV command of the FTP protocol, the port assignment includes the following steps:
a) Judging whether the FTP control connection is already allocated with a port, and if the FTP control connection is already allocated with the port, directly using the already allocated port;
b) If the FTP control connection does not allocate a port, traversing and searching a first port which does not contain the client IP address from a memory data mapping table of the allocated port, namely the client IP address is not in a mapping table map < FTP client IP address, FTP control connection >, if the port is found, newly adding the client address in an allocated address item, namely inserting < FTP client IP address, FTP control connection > record in a mapping table corresponding to the port in a memory data mapping table AssignPortMap of the allocated port;
c) If the memory data mapping table assignPortMap traversing the allocated ports does not have ports meeting the conditions, namely, the allocated ports do not have ports meeting the conditions, a reserved port number is taken out from a queue head pop of a memory data queue ReservPortQueue of an idle reserved port number for allocation, data connection is established at the same time, and the port number is added into an assignPortMap data structure after bind and list operation is successfully executed.
As shown in fig. 2, after the subsequent FTP server sends the allocated destination port number to the FTP client, the FTP server calls an accept to wait for the FTP client to establish a data connection; after receiving the data connection request, the FTP server checks the IP address of the FTP client of the data connection, searches the corresponding FTP control connection from the memory data mapping table of the allocated port according to the destination port number and the IP address of the FTP client, and establishes the corresponding relation between the FTP control connection and the FTP data connection; so far, the data connection between the FTP server and the FTP client is successfully established, and data communication can be carried out.
Each process of the FTP server reserves and manages a certain number of TCP ports in advance. For different PASV commands connected with each FTP control, the same TCP port is repeatedly used; the same TCP port is allocated for FTP client PASV commands from different IP addresses. After the FTP server completes the establishment of the data connection, the data connection is determined to find the corresponding FTP control connection according to the destination TCP port and the IP address of the client of the data connection. The multiplexing of the TCP ports is realized, and the problem that the FTP server cannot provide service due to insufficient TCP ports during high concurrent access is solved; for different file transmission connected with the same FTP control, the same port can be multiplexed, and the program operation efficiency is improved.
The invention can improve the use efficiency of the TCP port of the FTP server and solve the problems of failed port binding, repeated retry and the like in the traditional TCP port distribution mode.
In an embodiment of the TCP port multiplexing method facing the FTP protocol, in step S3, when the FTP server receives a PASV command sent by the FTP client over an FTP control connection of a process, after determining whether the PASV command has been assigned a port number, the method further includes:
and step S8, when the FTP control connection is to be closed, deleting < the IP address of the FTP client under the port number corresponding to the FTP control connection to be closed and the record of the FTP control connection to be closed in a memory data mapping table with the allocated port number.
In an embodiment of the TCP port multiplexing method facing the FTP protocol, in step S8, when the FTP control connection is closed, after deleting the < FTP client IP address, FTP control connection > record under the corresponding port number in the memory data mapping table to which the port number has been allocated, the method further includes:
step S9, judging whether other < FTP client IP address, FTP control connection > records exist under the port number corresponding to the closed FTP control connection in the memory data mapping table of the allocated port number,
and if no record exists, deleting the port number corresponding to the closed FTP control connection by the memory data mapping table with the allocated port number, and adding the deleted port number to the tail part of the memory data queue of the idle reserved port number.
Here, as shown in fig. 4, when the FTP control connection is closed, TCP port reclamation needs to be performed, and the port reclamation includes the following steps:
a) In the AssignPortMap set, according to the port number taken out from the control connection, deleting the corresponding client IP address record in the < port number, < client IP address, FTP control connection > > such as < FTP client IP address, FTP control connection > record to be closed;
b) For the TCP port number, if the record of < FTP client IP address and FTP control connection > exists, which indicates that other control connections exist to use the port, the recovery only deletes one record of < FTP client IP address and FTP control connection > of the AssignPortMap, and does not do other recovery actions;
c) For the TCP port, if all < FTP client IP address, FTP control connection > records under the port number are deleted, the port is added to the tail of ReservePortQueue after deleting the port record in the AssignPortMap, and the next allocation can be used continuously.
In an embodiment of the TCP port multiplexing method oriented to the FTP protocol, in step S7, inserting the retrieved port number and the FTP client IP address corresponding to the PASV command into the memory data mapping table of the allocated port number, where the FTP control connection > record corresponding to the PASV command includes:
and step S71, establishing data connection between the FTP client and the FTP server based on the port number, after the data connection is successfully established, inserting the taken port number and the IP address of the FTP client corresponding to the PASV command, the FTP control connection record corresponding to the PASV command into a memory data mapping table of the allocated port number, and establishing a corresponding relation between the data connection and the FTP control connection.
According to another aspect of the present invention, there is also provided a computer-readable storage medium having stored thereon computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, cause the processor to:
reserving different port number sets for processes of different FTP servers, wherein the reserved port number sets of any two processes are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, judging whether the PASV command has allocated a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
if the port is not searched in the memory data mapping table of the allocated port in a traversal manner, taking out a port number from the head of the memory data queue of the idle reserved port number of the corresponding process, sending the taken out port number to the FTP client, and inserting the taken out port number and the IP address of the FTP client corresponding to the PASV command, wherein the FTP control connection > record corresponding to the PASV command into the memory data mapping table of the allocated port number.
According to another aspect of the present invention, there is also provided a calculator apparatus, including:
a processor; and
a memory arranged to store computer executable instructions that, when executed, cause the processor to:
reserving different port number sets for processes of different FTP servers, wherein any two process reserved port number sets are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, judging whether the PASV command has allocated a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
Compared with the prior art, each process of the FTP server reserves a certain number of TCP ports in advance and manages the TCP ports. For different PASV commands connected with each FTP control, the same TCP port is repeatedly used; the same TCP port is allocated for FTP client PASV commands from different IP addresses. After the FTP server completes the establishment of the data connection, the data connection is determined to find the corresponding FTP control connection according to the destination TCP port and the IP address of the client of the data connection. The multiplexing of the TCP ports is realized, and the problem that the FTP server cannot provide service due to insufficient TCP ports during high concurrent access is solved; and for different file transmissions connected with the same FTP control, the same port can be multiplexed, and the program operation efficiency is improved.
In the present specification, the embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. A TCP port multiplexing method facing to FTP protocol is characterized by comprising the following steps:
reserving different port number sets for processes of different FTP servers, wherein any two process reserved port number sets are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, the FTP server judges whether the PASV command allocates a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
2. The method for multiplexing TCP ports according to claim 1, wherein the FTP server, upon receiving a PASV command sent by the FTP client over the FTP control connection of a process, determines whether the PASV command has been assigned a port number, further comprising:
and when the FTP control connection is to be closed, deleting < the IP address of the FTP client under the port number corresponding to the FTP control connection to be closed and the record of the FTP control connection to be closed in a memory data mapping table of the allocated port number.
3. The method for multiplexing TCP ports according to the FTP protocol of claim 2, wherein when the FTP control connection is closed, after deleting the < FTP client IP address, FTP control connection > record under the corresponding port number in the memory data mapping table to which the port number has been allocated, further comprising:
judging whether other < IP address of FTP client, FTP control connection > records exist under the port number corresponding to the closed FTP control connection in the memory data mapping table of the allocated port number,
and if no record exists, deleting the port number corresponding to the closed FTP control connection by the memory data mapping table with the allocated port number, and adding the deleted port number to the tail part of the memory data queue of the idle reserved port number.
4. The method for multiplexing TCP ports according to claim 1, wherein the step of inserting the retrieved port number and its < FTP client IP address corresponding to the PASV command into the memory data mapping table of the allocated port number includes:
establishing data connection between the FTP client and the FTP server based on the port number;
and after the data connection is successfully established, inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command, wherein the FTP control connection > record corresponding to the PASV command is inserted into the memory data mapping table of the allocated port number, and establishing the corresponding relation between the data connection and the FTP control connection.
5. A TCP port multiplexing device oriented to the FTP protocol, comprising:
the reservation unit is used for reserving different port number sets for the processes of different FTP servers, wherein any two process reserved port number sets are different;
an initialization unit, configured to initialize a memory data mapping table of an allocated port number and a memory data queue of an idle reserved port number of each process, where a total number of allocated ports and idle reserved ports of each process is equal to a total number of ports in a port set reserved by the process, and the memory data mapping table of allocated ports is: port number, map < client IP address, FTP control connection > >;
the system comprises a judging unit, a processing unit and a processing unit, wherein the judging unit is used for judging whether a port number is already allocated to a PASV command when the PASV command sent by an FTP client on FTP control connection of a certain process is received, and sending the allocated port number to the FTP client if the port is already allocated; if no port is allocated, acquiring a client IP address corresponding to the PASV command, judging whether a port number which does not contain a first FTP client IP address corresponding to the PASV command is searched in a memory data mapping table of an allocated port number of a corresponding process in a traversing manner, if the port number is searched in the memory data mapping table of the allocated port number in a traversing manner, inserting < the FTP client IP address corresponding to the PASV command in a port number which is searched in the memory data mapping table of the allocated port number in a traversing manner and does not contain the first FTP client IP address corresponding to the PASV command, recording a control connection > corresponding to the PASV command into a memory data mapping table, and sending the port number which does not contain the first FTP client IP address corresponding to the PASV command to the FTP client; and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
6. The TCP port multiplexing device oriented to the FTP protocol as described in claim 5, further comprising a recycle unit, configured to delete < FTP client IP address and FTP control connection > record under the corresponding port number of the FTP control connection to be closed in the memory data mapping table to which the port number has been allocated when the FTP control connection is to be closed.
7. The TCP port multiplexing device oriented to the FTP protocol as described in claim 6, wherein said recycle unit is further configured to determine whether there are other < IP address of FTP client, FTP control connection > records under the port number corresponding to the closed FTP control connection in the memory data mapping table of the allocated port number, and if there is no record, the memory data mapping table of the allocated port number deletes the port number corresponding to the closed FTP control connection and adds the deleted port number to the tail of the memory data queue of the free reserved port number.
8. The FTP-protocol-oriented TCP port multiplexing device of claim 1, wherein the determining unit is further configured to establish a data connection between the FTP client and the FTP server based on the port number; and after the data connection is successfully established, inserting the taken port number and the FTP client IP address corresponding to the PASV command into a memory data mapping table of the allocated port number according to the FTP control connection > record corresponding to the PASV command, and establishing a corresponding relation between the data connection and the FTP control connection.
9. A computer-readable storage medium having computer-executable instructions stored thereon, wherein the computer-executable instructions, when executed by a processor, cause the processor to:
reserving different port number sets for processes of different FTP servers, wherein the reserved port number sets of any two processes are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, judging whether the PASV command has allocated a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
10. A calculator device, comprising:
a processor; and
a memory arranged to store computer executable instructions that, when executed, cause the processor to:
reserving different port number sets for processes of different FTP servers, wherein the reserved port number sets of any two processes are different;
initializing a memory data mapping table of the allocated port number and a memory data queue of an idle reserved port number of each process, wherein the total number of the allocated port and the idle reserved port of each process is equal to the total number of ports in a port set reserved by the process, and the memory data mapping table of the allocated port is as follows: port number, map < client IP address, FTP control connection > >;
when receiving a PASV command sent by an FTP client on the FTP control connection of a certain process, judging whether the PASV command has allocated a port number or not,
if the port is allocated, the allocated port number is sent to the FTP client;
if no port is allocated, acquiring the client IP address corresponding to the PASV command, judging whether to search the port number of the first FTP client IP address not including the PASV command in a traversal way from the memory data mapping table of the allocated port number of the corresponding process,
if the port number is found in the memory data mapping table with the allocated port number in a traversing manner, inserting < the IP address of the FTP client corresponding to the PASV command into the port number which is found in the memory data mapping table with the allocated port number in a traversing manner and does not contain the IP address of the FTP client corresponding to the PASV command, recording the control connection > corresponding to the PASV command into the memory data mapping table, and sending the port number which does not contain the IP address of the FTP client corresponding to the PASV command to the FTP client;
and if the memory data mapping table of the allocated port is not searched in a traversing way, taking out a port number from the head of the memory data queue of the idle reserved port number corresponding to the process, sending the port number to the FTP client, and inserting the port number taken out and the IP address of the FTP client corresponding to the PASV command into the memory data mapping table of the allocated port number, wherein the FTP control connection > record corresponding to the PASV command is inserted into the IP address of the FTP client corresponding to the PASV command.
CN202211271236.XA 2022-10-17 2022-10-17 TCP port multiplexing method and equipment for FTP Pending CN115665129A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211271236.XA CN115665129A (en) 2022-10-17 2022-10-17 TCP port multiplexing method and equipment for FTP

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211271236.XA CN115665129A (en) 2022-10-17 2022-10-17 TCP port multiplexing method and equipment for FTP

Publications (1)

Publication Number Publication Date
CN115665129A true CN115665129A (en) 2023-01-31

Family

ID=84989993

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211271236.XA Pending CN115665129A (en) 2022-10-17 2022-10-17 TCP port multiplexing method and equipment for FTP

Country Status (1)

Country Link
CN (1) CN115665129A (en)

Similar Documents

Publication Publication Date Title
JP5243405B2 (en) Method and system for managing computing resources
US9003002B2 (en) Efficient port management for a distributed network address translation
CN104219127B (en) A kind of creation method and equipment of virtual network example
US7065526B2 (en) Scalable database management system
US8125993B2 (en) Network element having a DHCP lease timer
KR100725066B1 (en) A system server for data communication with multiple clients and a data processing method
CN103607428B (en) A kind of method and apparatus for accessing shared drive
EP3748934B1 (en) Mirror pull method and system therefor
CN107105050B (en) Storage and downloading method and system for service objects
CN111327668B (en) Network management method, device, equipment and storage medium
JP2000507428A (en) Client management flow control method and apparatus on finite memory computer system
CN109600410B (en) Data storage system and method
CN114070822B (en) Kubernetes Overlay IP address management method
US20110282917A1 (en) System and method for efficient resource management
CN110798507B (en) Method and system for DHCP address allocation memory
CN113242293A (en) UPF equipment, data processing and capacity expansion method and device
CN110909030B (en) Information processing method and server cluster
CN114422519B (en) Data request processing method and device, electronic equipment and storage medium
CN111294220B (en) Nginx-based network isolation configuration method and device
CN115665129A (en) TCP port multiplexing method and equipment for FTP
CN110324436B (en) Proxy method and device for transport layer proxy
CN115396510B (en) Communication method and communication module
WO2022089147A1 (en) Method for acquiring address, apparatus and system
CN114866854A (en) Video access mode dynamic allocation method, system, electronic equipment and storage medium
US20060168108A1 (en) Methods and systems for defragmenting subnet space within an adaptive infrastructure

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination