Shared data port file transmission method compatible with FTP protocol
By introducing a mechanism of shared data ports and unique identifiers in the FTP protocol, the problem that traditional FTP protocol needs to open a large number of ports in passive mode is solved, which improves security and network management simplification, and supports high concurrent file transfer.
Patent Information
- Application Number
- CN202411920561.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-03-14
AI Technical Summary
Traditional FTP protocols need to dynamically open a large number of data ports in passive mode, resulting in increased server security risks, increased network management complexity and increased resource consumption.
The shared data port file transfer method is adopted that is compatible with the FTP protocol. The client sends control commands to the server before sending the passive mode command. The server uses the preset shared data port for data transmission, and distinguishes the requests of different clients through unique identifiers.
Reduces the number of ports that the server needs to open, reduces security risks, simplifies network management, and reduces resource consumption, while supporting high concurrent file transfers.
Smart Images

Figure CN119629168A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet communication technology, and in particular to a file transmission method based on a client-server architecture, and specifically to a shared data port file transmission method compatible with a file transfer protocol (FTP). Background Art
[0002] In Internet applications, file transfer is a basic and important function. As a network protocol with a long history and wide application, File Transfer Protocol (FTP) is widely used to upload and download files between clients and servers. The FTP protocol adopts a client-server architecture and implements file transfer through control channels and data channels.
[0003] In the passive mode of the traditional FTP protocol, in order to support multiple concurrent connections, the server needs to dynamically open a new data port for each data connection. This method requires the server to maintain a large number of open ports, which brings the following technical problems:
[0004] Increased server security risks: Opening too many ports will expand the attack surface of the server and increase the risk of malicious attacks.
[0005] Increased network management complexity: Firewall policies need to be configured to allow connections on these dynamic ports, increasing the complexity of network management.
[0006] Resource consumption: Maintaining a large number of connections and ports consumes system resources of the server.
[0007] In order to solve the above problems, there are also some improvement schemes in the prior art, but there are still certain limitations. For example, some schemes may need to modify the FTP protocol implementation of the client or server, resulting in compatibility issues.
[0008] Therefore, there is an urgent need for an improved FTP file transfer method that can reduce the number of data ports that need to be opened by the server while being compatible with the existing FTP protocol, thereby improving security, simplifying network management and reducing resource consumption. Summary of the invention
[0009] The purpose of the present invention is to overcome the technical defect that a large number of data ports need to be opened in the passive mode of the existing FTP protocol to support multiple concurrent connections, and to provide a shared data port file transmission method compatible with the FTP protocol to reduce the number of ports that need to be opened by the server, improve network security, and simplify network management.
[0010] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0011] The present invention provides a shared data port file transmission method compatible with FTP protocol, which is used for performing file transmission between a client and a server, and comprises the following steps:
[0012] Before sending the passive mode command PASV, the client sends a control command to the server to instruct the server to use the shared data port of the server;
[0013] After receiving the control command, the server uses a preset shared data port to transmit data for subsequent file download or upload requests from the client;
[0014] The server generates a unique identifier for each file download or upload request, and establishes a mapping relationship between the unique identifier and the requested file path and stores the mapping relationship;
[0015] The server sends a response including the unique identifier to the client;
[0016] After connecting to the shared data port, the client sends the unique identifier to the server for the server to identify the corresponding file transfer request.
[0017] Furthermore, the control command instructing to use the shared data port of the server is a SHPT command.
[0018] Furthermore, the server sends a response including the unique identifier to the client by responding to the client's request to download or upload a file and using status code 290.
[0019] Further, the unique identifier is a universal unique identifier (UUID).
[0020] Furthermore, the file download or upload request includes a RETR command or a STOR command.
[0021] Furthermore, the server has one preset shared data port.
[0022] Furthermore, after the client connects to the shared data port, the client sends the unique identifier and the requested file path to the server.
[0023] Furthermore, after receiving the unique identifier and the requested file path, the server verifies the mapping relationship between the unique identifier and the file path, and allows file transfer on the shared data port if the mapping relationship exists.
[0024] The shared data port file transfer method compatible with the FTP protocol designed by the present invention can bring many advantages. First, by introducing the mechanism of shared data port, the server side only needs to open a preset data port to support multiple concurrent connections. The application of this mechanism significantly reduces the number of ports required to be maintained by the server, thereby effectively reducing the risk of the server being attacked and improving the overall network security performance. Secondly, due to the reduction in the number of server ports, the configuration of the firewall policy is also simplified, which reduces the complexity of network management work to a certain extent. Furthermore, the present invention is expanded on the basis of the existing FTP protocol, and the shared data port function is realized by adding control commands and response status codes, and good compatibility is maintained with the existing FTP protocol. The function of the present invention can be used without large-scale transformation of the existing FTP client, and has strong practicality. In addition, by using the shared data port and the unique identifier, the present invention can support multiple clients to transfer files at the same time, meeting the application requirements in high-concurrency scenarios. Finally, by reducing the number of connections and ports that the server needs to maintain, the present invention also has certain advantages in reducing server resource consumption. In summary, the technical solution adopted by the present invention can bring many benefits to practical applications from multiple angles and has broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a timing diagram of the method described in Example 1. DETAILED DESCRIPTION
[0026] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0027] Example 1.
[0028] like Figure 1 As shown, the shared data port file transmission method compatible with the FTP protocol described in this embodiment describes the process in which the client A and the client B respectively establish connections with the server and download files.
[0029] Client A's file download process:
[0030] Establish a control connection (corresponding to Figure 1 "Establish connection" to "230Loggedon"): Client A first establishes a TCP control connection with the server, and the server listens to the file transfer control port (for example, port 21). Client A sends the USER command and the PASS command in sequence for identity authentication. After the server passes the authentication, it returns the 230Loggedon response code, indicating that the login is successful.
[0031] Set the transfer mode (corresponding to Figure 1 "TYPEI" to "200TypesettoI"): Client A sends the TYPEI command to specify the binary mode for file transfer. The server returns a 200TypesettoI response code, indicating that the transfer mode is set successfully.
[0032] Switch working directory (corresponding to Figure 1 "CWDdirectory" to "250CWDsuccessful."directory"iscurrentdirectory."): Client A sends the CWD / data command to switch the working directory to the / data directory. The server returns a response code of 250CWDsuccessful." / data"iscurrentdirectory.", indicating that the directory switch is successful.
[0033] Send a shared port request (corresponding to Figure 1 "SHPT" and "200Sharedataport"): Client A sends the control command SHPT to instruct the server to use the shared data port. After receiving the SHPT command, the server confirms that the shared data port has been opened. If it is not opened, it will open it and will not close it again. Then it returns the 200Sharedataport response code, indicating that it is ready to use the shared data port. (Note: Figure 1 The "200 Share data port" is a non-standard FTP response, which is customized in this embodiment.)
[0034] Initiate a passive mode request (corresponding to Figure 1 "PASV" and "227EnteringPassiveMode(h1,h2,h3,h4,p1,p2)"): Client A sends the passive mode command PASV. After receiving the PASV command, the server no longer opens a new data port like traditional FTP, but returns the IP address and port number of the pre-configured shared data port, such as 227EnteringPassiveMode(192,168,1,100,4,20), where the port number is 1044. (Note: Although the 227 response is returned, the port number it carries points to the shared data port, not the newly opened port.)
[0035] Initiate a download request (corresponding to Figure 1In the above example, "RETR file" and "150 Opening data channel for file download from server of "file""): Client A sends a download command RETR file_a.txt to request download of a file named file_a.txt. The server receives the RETR command.
[0036] Generate UUID and send (corresponding to Figure 1 "Generate UUID and file mapping" and "290UUIDofsharingport"): The server generates a unique UUID, such as a1b2c3d4-e5f6-7890-1234-567890abcdef, and maps the UUID to the requested file path / data / file_a.txt and stores it. The server then sends a custom response code 290UUIDofsharingporta1b2c3d4-e5f6-7890-1234-567890abcdef to client A. (Note: Figure 1 "290UUIDofsharingport" is a customized response in this embodiment.)
[0037] Establish a data connection and send the UUID and file name (corresponding to Figure 1 "Establish connection" and "Send UUID and file name"): Client A uses the shared data port information obtained in the previous steps to establish a TCP data connection with the server. After the connection is successfully established, Client A sends the received UUID: a1b2c3d4-e5f6-7890-1234-567890abcdef and the requested file name file_a.txt to the server. (Note: Figure 1 "Sending UUID and file name" is the data channel transmission content newly added by the present invention. )
[0038] Verify UUID (corresponding to Figure 1 "Verify UUID and file mapping"): After receiving the UUID and file name, the server searches for the previously stored mapping relationship based on the received UUIDa1b2c3d4-e5f6-7890-1234-567890abcdef. If the file path / data / file_a.txt corresponding to the UUID is found, the verification is successful.
[0039] Data transmission (corresponding to Figure 1"Sending file byte stream" and "226 Successfully transferred "filename""): After verification, the server reads the file content from / data / file_a.txt and sends the file data to client A through the shared data port. After the data transmission is completed, the server sends a 226 Successfully transferred "file_a.txt" response code on the control connection, indicating that the file transfer is complete.
[0040] Close the connection (corresponding to Figure 1 "QUIT" to "Close Connection"): Client A sends a QUIT command to request to close the control connection. The server returns a 221Goodbye response code and closes the control connection. The data connection is closed after the file transfer is completed.
[0041] In some cases, two clients, namely client A and client B, may send requests to the server at the same time. The differences between this and the above single client transmission method are as follows:
[0042] The server distinguishes data streams based on UUID: The data stream received by the server on the shared data port will contain the UUID and file name sent by the client. The server will distinguish the requests of the two clients based on the UUID and find the corresponding mapping relationship.
[0043] When the server receives data starting with UUID_A on the shared data port, it recognizes that this is a request from client A, finds file_a.txt based on the mapping relationship, and then sends the data of file_a.txt back to the data connection.
[0044] When the server receives data starting with UUID_B, it recognizes that this is a request from client B, finds file_b.txt based on the mapping relationship, and then sends the data of file_b.txt back to another data connection (if client B establishes another connection) or distinguishes the data in the current connection.
[0045] It can be seen from the above embodiment that when downloading files, both client A and client B use the same shared data port preset by the server for data transmission. The server generates a unique UUID for each client's request and establishes a mapping relationship between the UUID and the file path, thereby being able to distinguish data transmission requests from different clients and ensuring the correctness of concurrent file transmission. This effectively solves the problem that the traditional FTP protocol needs to open multiple data ports in passive mode, reduces the port occupancy of the server, improves security and simplifies network management.
[0046] It is worth emphasizing that in the present invention, after receiving the download request from the client, the server does not directly send the file content through the shared data port, but first generates and returns a UUID, and waits for the client to send the UUID again after establishing a data connection. This seemingly additional step is actually the key to achieving concurrent file transmission on the shared data port.
[0047] Imagine that if the server immediately starts sending files through the shared data port after receiving the RETR command, and multiple clients simultaneously request to download different files, the server will not be able to distinguish which client's file transfer request belongs to the data connection currently established on the shared data port, which can easily cause data confusion, file transfer errors, and even security risks. In addition, the lack of clear request identification will also make permission control and auditing difficult.
[0048] The introduction of UUID effectively solves the above problems. Each UUID uniquely corresponds to a client's download request for a specific file, and it is like a temporary "pass". The server associates the UUID with the requested file path. After the data connection is established, the client sends the UUID, which is equivalent to using the "pass" to declare its identity and request to the server. By verifying the UUID, the server can accurately route the data to the corresponding client, ensuring the correctness and security of data transmission.
[0049] Therefore, through the UUID mechanism, the present invention realizes clear distinction and safe processing of concurrent file transfer requests in an environment of shared data ports, which is the key to ensuring its technical effect.
[0050] In the description of the present invention, it should be noted that the terms "vertical", "up", "down", "horizontal", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0051] In the description of the present invention, it is also necessary to explain that, unless otherwise clearly specified and limited, the terms "set", "install", "connect", and "connect" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0052] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A shared data port file transmission method compatible with FTP protocol, used for transferring files between a client and a server, characterized in that: The following steps are involved: Before sending the passive mode command PASV, the client sends a control command to the server to instruct the server to use the shared data port of the server; After receiving the control command, the server uses a preset shared data port to transmit data for subsequent file download or upload requests from the client; The server generates a unique identifier for each file download or upload request, and establishes a mapping relationship between the unique identifier and the requested file path and stores the mapping relationship; The server sends a response including the unique identifier to the client; After connecting to the shared data port, the client sends the unique identifier to the server for the server to identify the corresponding file transfer request.
2. The shared data port file transmission method compatible with FTP protocol according to claim 1, characterized in that: The control command instructing to use the shared data port of the server is a SHPT command.
3. The shared data port file transmission method compatible with FTP protocol according to claim 1, characterized in that: The server sends a response including the unique identifier to the client by responding to the client's request to download or upload a file and using status code 290.
4. The shared data port file transmission method compatible with FTP protocol according to claim 1, characterized in that: The unique identifier is a Universally Unique Identifier (UUID).
5. The shared data port file transmission method compatible with FTP protocol according to claim 1, characterized in that: The file download or upload request includes a RETR command or a STOR command.
6. The shared data port file transmission method compatible with FTP protocol according to claim 1, characterized in that: After the server receives the control command to use the server shared data port, if the port is not opened, it is opened and will not be closed again; and there is only one preset shared data port.
7. The shared data port file transmission method compatible with FTP protocol according to claim 1, characterized in that: After the client is connected to the shared data port, the client sends the unique identifier and the requested file path to the server.
8. The shared data port file transmission method compatible with FTP protocol according to claim 7, characterized in that: After receiving the unique identifier and the requested file path, the server verifies the mapping relationship between the unique identifier and the file path, and allows file transfer on the shared data port if the mapping relationship exists.