FTP (File Transfer Protocol) file downloading method and device based on swan mongolian system, and storage medium
By responding to FTP synchronization requests in the sandbox of the Hongmeng system and using worker to download files through multiple threads, the problem of the Hongmeng system lacking direct FTP support is solved, efficient FTP file download is achieved, and the system's file transfer capability is improved.
Patent Information
- Application Number
- CN202510117165.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2045-01-24
AI Technical Summary
The Hongmeng system lacks direct FTP support, which limits the implementation of FTP file download function and requires additional time and energy to adapt.
Respond to the FTP synchronization request in the sandbox of the Hongmeng system, obtain the login information of the FTP server, log in to the FTP server, switch to binary mode, obtain the download address and port number of the target file, and download the target file through the worker of the Hongmeng system multi-thread.
It provides a stable FTP file download solution, effectively realizes the efficient transmission of FTP files, and enhances the functions and compatibility of the Hongmeng system in the file transfer field.
Smart Images

Figure CN119697178A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an FTP file downloading method, device and storage medium based on the Hongmeng system. Background Art
[0002] In today's digital age, the operating system is the core link between users and devices, and its richness and perfection of functions are crucial. As an emerging operating system, Hongmeng system has created an efficient application development environment for developers with its rich APIs and development tools, as well as support for multiple network communication protocols, to help the birth of various innovative applications. However, in the key area of network file transfer, Hongmeng system currently does not provide direct FTP support, and the official has not launched a dedicated FTP-related API interface. This makes it impossible for developers to use the system's own resources when implementing the FTP file download function. In sharp contrast, the Android system, with its mature ecology and open capabilities, has bred widely used and well-verified third-party FTP libraries such as Apache Commons Net, which can stably meet FTP operation requirements. However, due to the lack of direct support for the FTP protocol and the uncertainty of the compatibility of third-party FTP libraries, the implementation of the FTP file download function on the Hongmeng platform has been limited to a certain extent, and additional time and effort need to be invested in adaptation work. Summary of the invention
[0003] The purpose of this application is to solve at least one of the above-mentioned technical defects, especially the technical defects in the prior art that limit the implementation of the FTP file download function on the Hongmeng platform.
[0004] In a first aspect, the present application provides an FTP file download method based on the Hongmeng system, the method comprising:
[0005] In the sandbox of the Hongmeng system, in response to the FTP synchronization request, the login information of the FTP server is obtained from the FTP synchronization request, and the login information is used to log in to the FTP server;
[0006] When the FTP server is successfully logged in, the FTP server is instructed to switch to binary mode, and then, according to the target file directory obtained, the FTP server is instructed to enter the target file directory, and the download address and download port number of the target file returned by the FTP server are received;
[0007] According to the download address and download port number, a data transmission connection is established with the FTP server, and the target file is downloaded through the worker multi-threading of the Hongmeng system. When the target file is downloaded, the data transmission connection is closed.
[0008] In one embodiment, the login information includes an FTP server IP address, an FTP server port number, a user name and a corresponding password; and the steps of logging into the FTP server using the login information include:
[0009] Initiate a connection request to the FTP server based on the FTP server IP address and FTP server port number;
[0010] When it is determined that the connection with the FTP server is successful, a username request is sent to the FTP server according to the username, so that the FTP server verifies the username;
[0011] When it is determined that the username verification is successful, a password request is initiated to the FTP server according to the password corresponding to the username, so that the FTP server verifies the password, and when it is determined that the password verification is successful, the login to the FTP server is confirmed.
[0012] In one embodiment, after instructing the FTP server to switch to binary mode, according to the acquired target file directory, instructing the FTP server to enter the target file directory, and receiving the download address and download port number of the target file returned by the FTP server, the steps include:
[0013] Send a binary file type request to the FTP server to switch the FTP server to binary mode;
[0014] When it is determined that the FTP server is switched to the binary mode, a working directory switching request is initiated to the FTP server according to the acquired target file directory, so that the FTP server switches to the target file directory;
[0015] When it is determined that the FTP server has entered the target file directory, a passive mode request is initiated to the FTP server, and the download address and download port number of the target file returned by the FTP server are received.
[0016] In one embodiment, after the step of establishing a data transmission connection with an FTP server according to the download address and the download port number, the method further includes:
[0017] Generate a permission request box according to the file information of the target file to request the user for permission to download the file;
[0018] When authorization is obtained, if it is determined that the file information of the target file contains sensitive information, the sensitive information is anonymized.
[0019] In one embodiment, the step of downloading the target file through the worker multi-thread of the Hongmeng system includes:
[0020] Create a worker multithreaded program in Hongmeng system to manage the download queue, which contains a list of target files.
[0021] In worker multithreading, a polling mechanism is used to download the target file.
[0022] In one embodiment, the method further comprises:
[0023] If the target file is a large file, use the file system API of Hongmeng system in read-write mode to open the local storage folder used to store the downloaded file;
[0024] When each data packet of the target file sent by the FTP server is received, the file writing method is called to write the received data packet to the end of the storage folder.
[0025] In one embodiment, the method further comprises:
[0026] Use the API set for network communication in the Hongmeng system to connect to the network.
[0027] In a second aspect, the present application also provides an FTP file downloading device based on the Hongmeng system, the device comprising:
[0028] An FTP server login module is used to, in the sandbox of the Hongmeng system, respond to an FTP synchronization request, obtain the login information of the FTP server from the FTP synchronization request, and use the login information to log in to the FTP server;
[0029] The download address acquisition module is used to instruct the FTP server to switch to binary mode after successfully logging into the FTP server, and then instruct the FTP server to enter the target file directory according to the acquired target file directory, and receive the download address and download port number of the target file returned by the FTP server;
[0030] The target file download module is used to establish a data transmission connection with the FTP server according to the download address and download port number, and download the target file through the worker multi-threading of the Hongmeng system. When the target file is downloaded, the data transmission connection is closed.
[0031] In the third aspect, the present application provides a storage medium: the storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the FTP file download method based on the Hongmeng system as described in any of the above embodiments.
[0032] In a fourth aspect, the present application provides a computer device, comprising: one or more processors, and a memory;
[0033] Computer-readable instructions are stored in the memory. When the computer-readable instructions are executed by one or more processors, the steps of the FTP file download method based on the Hongmeng system in any of the above-mentioned embodiments are performed.
[0034] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0035] The FTP file download method, device and storage medium based on the Hongmeng system provided in this application respond to FTP synchronization requests in the Hongmeng system sandbox, successfully obtain and use the login information of the FTP server to log in, then switch to binary mode, obtain the download address and port of the target file, and establish a data transmission connection. The file is downloaded using the worker multi-threading technology of the Hongmeng system, and the connection is closed after the download is completed. This method solves the problem of the lack of direct FTP support in the Hongmeng system, provides a stable FTP file download solution, effectively realizes the efficient transmission of FTP files, and enhances the function and compatibility of the Hongmeng system in the field of file transfer. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0037] Figure 1 A flowchart of an FTP file download method based on the Hongmeng system provided in an embodiment of the present application;
[0038] Figure 2 An example diagram of an FTP file download method based on the Hongmeng system provided in an embodiment of the present application;
[0039] Figure 3 A schematic diagram of the structure of an FTP file download device based on the Hongmeng system provided in an embodiment of the present application;
[0040] Figure 4 A schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0042] The present application provides an FTP file download method based on the Hongmeng system. The following embodiments are described by taking the method applied to a computer device equipped with the Hongmeng system as an example. It can be understood that the computer device can be any device with data processing functions, including but not limited to a single server, a server cluster, a personal laptop, a desktop computer, etc. Among them, the method can be a client application on a computer device interacting with an FTP server. Figure 1 As shown, the method may include the following steps:
[0043] S101: In the sandbox of the Hongmeng system, in response to an FTP synchronization request, obtain the login information of the FTP server from the FTP synchronization request, and use the login information to log in to the FTP server.
[0044] Among them, the sandbox of the Hongmeng system is a virtualized isolation environment used to run and manage applications, ensuring that applications are executed in a secure isolation space to avoid affecting other parts of the system and enhancing the security and stability of the operating system. FTP synchronization request is a request issued by the client to establish a connection with the FTP server and perform file transfer operations, usually including details such as FTP server login information, target file directory, and data transmission method. The login information of the FTP server refers to the authentication information that the FTP server requires the client to provide, usually including a user name and password to ensure that only authorized users can access the resources in the FTP server. The FTP server is a server used to store and manage files, allowing operations such as uploading, downloading, and deleting files through the FTP protocol.
[0045] In this step, first, respond to the FTP synchronization request from the client. When the client initiates the request, the request signal is received and processed accordingly according to the content of the request to ensure that the subsequent steps can proceed smoothly. Then, the login information of the FTP server is obtained from the request, which may include a user name and password, to ensure successful connection and interaction with the FTP server, and extracting this information is to prepare for identity authentication and connection establishment. Subsequently, the FTP server is logged in using the obtained login information, which may be by sending a user name and password to the FTP server, waiting for the return of the FTP server authentication information, and if the authentication is successful, the connection with the FTP server is established, and preparations are made for subsequent data transmission.
[0046] It can be understood that in the sandbox of the Hongmeng system, responding to FTP synchronization requests and obtaining the login information of the FTP server can ensure the correct communication between the Hongmeng system and the FTP server. Through the sandbox mechanism, the Hongmeng system isolates applications and limits the application's access to system resources and files. In this way, only when the application is explicitly authorized can the login information of the FTP server be obtained and the login operation be completed in the sandbox. This isolation mechanism effectively prevents applications from accessing sensitive data without authorization and reduces potential security risks.
[0047] By correctly extracting and using this login information for authentication, it is possible to successfully log in to the FTP server and establish a connection with it, thereby achieving secure and efficient file transfer. Because the sandbox provides additional security protection, the Hongmeng system is able to provide a more stable and controlled communication channel while ensuring data privacy. The sandbox not only protects the Hongmeng system itself from malicious applications, but also ensures that data during file transfer is not illegally tampered with or leaked. Therefore, this method can avoid the risk of illegal access while providing a reliable foundation for subsequent data transfer operations.
[0048] S102: When the FTP server is successfully logged in, the FTP server is instructed to switch to binary mode, and according to the acquired target file directory, the FTP server is instructed to enter the target file directory, and the download address and download port number of the target file returned by the FTP server are received.
[0049] Among them, binary mode is a data transmission mode in the FTP protocol, which is suitable for transmitting non-text files, such as pictures, videos, audio, etc. Binary mode can ensure that the file is not modified or any data is lost during the transmission process. The target file directory refers to the specific path where the target file is stored in the FTP server. During the file download process, it is necessary to instruct the FTP server to enter the directory in order to find and transfer the specified file. The download address is a resource location identifier returned by the FTP server, which is used to indicate the exact location or URL of the target file on the FTP server. Based on this address, the specific data of the file can be requested from the FTP server. The download port number is a network port number provided by the FTP server, which is used to establish a data transmission connection. Through this port, data can be exchanged with the FTP server to complete the file download.
[0050] In this step, first, after successfully logging into the FTP server, it is necessary to ensure that no data format error or content loss occurs in the file transfer, especially for non-text files. Therefore, the FTP server is required to enter binary mode, for example, by sending a "TYPE I" command, to ensure that the file keeps the original data unchanged during the transmission process. Next, because the file is stored in a specific directory, if the correct directory is not switched to, the target file cannot be found. In an example, the FTP server can be told to jump to the directory containing the target file by sending a "CWD" command to ensure the accuracy of the file path. Subsequently, after receiving the instruction, the FTP server will provide the corresponding download address according to the actual storage location of the target file, and indicate which port should be used to perform data transmission with the FTP server. In this way, it is possible to ensure the stable connection with the FTP server and the efficient conduct of file transmission, avoid the failure of file transmission caused by format mismatch or directory error, thereby improving the reliability and efficiency of the whole file download process.
[0051] It can be understood that, first of all, instructing the FTP server to switch to binary mode ensures the integrity of the file data and avoids data damage or loss during the transmission process. Then, by instructing the FTP server to enter the target file directory, the path of the stored file can be accurately located. Finally, by receiving the download address and port number returned by the FTP server, the data transmission connection can be accurately established to ensure that the file can be downloaded from the FTP server to the local efficiently and stably.
[0052] S103: Establish a data transmission connection with the FTP server according to the download address and download port number, and download the target file through the worker multi-threading of the Hongmeng system. When the download of the target file is completed, close the data transmission connection.
[0053] Among them, the data transmission connection refers to the network connection established with the FTP server, through which the actual file transmission is performed, including uploading, downloading or deleting files. Worker multithreading is a mechanism in the Hongmeng system that supports parallel processing of tasks. It uses multiple threads to perform multiple operations simultaneously to improve task processing efficiency. In the file download scenario, worker multithreading technology can decompose the download task into multiple threads, thereby speeding up the file download process.
[0054] In this step, after obtaining the download address and port number, the next step is to establish a data transmission connection. You can initiate a request to the FTP server through the client and connect to the FTP server using the specified port number. For example, use a socket to connect to the download port of the FTP server to establish a data stream channel so that file data can be obtained from the FTP server. During the file download process, the worker multi-threading technology of the Hongmeng system is used to assign download tasks to multiple threads, and each thread is responsible for downloading part of the file. Through parallel execution, multiple threads can work at the same time, thereby speeding up the overall file download process. When the file download is complete, in order to free up resources and terminate the connection with the FTP server, a command can be sent to close the data transmission connection. For example, end the session by sending "QUIT" or a similar command to ensure that the connection is closed correctly to prevent waste of resources.
[0055] It can be understood that, first of all, establishing a data transmission connection is a prerequisite for ensuring that files can be downloaded from the FTP server. Through the network communication framework of the Hongmeng system, a stable data connection is established with the FTP server using the specified download address and port number to ensure the reliability of file transfer. The network stack and connection management mechanism of the Hongmeng system provide efficient support for this process. At the same time, the sandbox technology ensures that during the data exchange process, the application can only access its authorized network resources, thereby ensuring the security of the connection.
[0056] Next, with the help of Hongmeng's worker multi-threading technology, multiple threads can be started at the same time to download the target file in parallel. Hongmeng supports multi-task parallel processing, making full use of the system's multi-core processing capabilities to improve data transmission efficiency. When the network bandwidth is sufficient, parallel downloading of multiple threads can greatly increase the download speed and reduce waiting time. The efficient scheduling mechanism of Hongmeng ensures smooth resource allocation and execution of each thread, making the entire file download process smoother and more efficient.
[0057] Finally, after the file download is completed, by closing the data transmission connection, the occupied network and system resources can be released, avoiding unnecessary waste of resources caused by maintaining the connection for a long time. The resource management mechanism of the Hongmeng system will automatically clean up the relevant network and memory resources when closing the connection, thereby ensuring that system resources are used reasonably and avoiding system overload. This not only improves the stability and efficiency of file downloads, but also ensures the efficient operation and long-term stability of the system.
[0058] In the above embodiment, by responding to the FTP synchronization request in the Hongmeng system sandbox, the login information of the FTP server is successfully obtained and used to log in, and then the binary mode is switched to obtain the download address and port of the target file, and a data transmission connection is established. The worker multi-threading technology of the Hongmeng system is used to download files, and the connection is closed after the download is completed. This method solves the problem of the lack of direct FTP support in the Hongmeng system, provides a stable FTP file download solution, effectively realizes the efficient transmission of FTP files, and enhances the function and compatibility of the Hongmeng system in the field of file transfer.
[0059] In one embodiment, the login information includes an FTP server IP address, an FTP server port number, a user name and a corresponding password; and the steps of logging into the FTP server using the login information include:
[0060] Initiate a connection request to the FTP server based on the FTP server IP address and FTP server port number;
[0061] When it is determined that the connection with the FTP server is successful, a username request is sent to the FTP server according to the username, so that the FTP server verifies the username;
[0062] When it is determined that the username verification is successful, a password request is initiated to the FTP server according to the password corresponding to the username, so that the FTP server verifies the password, and when it is determined that the password verification is successful, the login to the FTP server is confirmed.
[0063] Among them, the FTP server IP address is the unique identifier of the FTP server in the network, which is used to specify the location of the target device when the client communicates with the server. The FTP server port number is the network port where the FTP service listens and receives connection requests. Usually, FTP uses port 21 by default for control connections. The username is an identifier registered on the FTP server to identify the user. Each FTP account has a unique username. The password is the verification information used in conjunction with the username to ensure that only authorized users can access resources on the FTP server. The connection request is a request sent to the FTP server to establish a network connection. It usually contains the IP address and port number of the FTP server and is used to specify the target for communication with the FTP server. The username request is a request sent to the FTP server to inform the FTP server of the username to be provided. The FTP server will then verify the legitimacy of the username. The password request is a request sent by the client to the FTP server, providing the password corresponding to the username. The FTP server will verify whether the password is correct and decide whether to authorize access.
[0064] Specifically, you first need to send a connection request to the FTP server, specify the server's IP address and port number, and use the TCP / IP protocol to try to establish a connection with the FTP server. When a request containing the FTP server's IP and port information is sent, the FTP server receives the request and waits for a response. After the connection request is successful, an available data transmission channel will be established with the FTP server. After the connection is successful, you need to send a request containing a username to the FTP server. This request is used to inform the FTP server of the username information to be provided. After receiving the username request, the FTP server will verify it based on its stored user data to check whether the username exists and is valid. After the username is successfully verified, the password corresponding to the username will be sent to the FTP server. The FTP server verifies the correctness of the password by matching it with the password stored in its database. When the FTP server verifies that the username and password are correct, it confirms that the login is successful, which means that the FTP server authorizes the client to access its resources, and the two parties can start subsequent data interaction.
[0065] In this embodiment, a connection request is initiated to the FTP server to ensure that the FTP server can be correctly found and connected. The following username and password verification process is to protect the FTP server resources and prevent unauthorized access. By sending username and password requests to the FTP server in sequence, the identity of the client is gradually confirmed. Only after the username and password are verified can the access authority be obtained. In this way, the security and accuracy of the file transfer operation are guaranteed, the intrusion of illegal users is avoided, and at the same time, only the correct identity authentication information can be passed, avoiding the risk of data leakage.
[0066] In one embodiment, after instructing the FTP server to switch to binary mode, according to the acquired target file directory, instructing the FTP server to enter the target file directory, and receiving the download address and download port number of the target file returned by the FTP server, the steps include:
[0067] Send a binary file type request to the FTP server to switch the FTP server to binary mode;
[0068] When it is determined that the FTP server is switched to the binary mode, a working directory switching request is initiated to the FTP server according to the acquired target file directory, so that the FTP server switches to the target file directory;
[0069] When it is determined that the FTP server has entered the target file directory, a passive mode request is initiated to the FTP server, and the download address and download port number of the target file returned by the FTP server are received.
[0070] Among them, the binary file type request is a command sent to the FTP server via the FTP protocol, requesting the FTP server to use binary mode to transfer files. Binary mode ensures that the file data will not change during the transmission process and is applicable to all types of files. The switch working directory request is a command sent to the FTP server via the FTP protocol, requesting the FTP server to switch to the directory where the target file is located. The passive mode request is to request the FTP server to enter the passive mode. At this time, the FTP server will not actively open a data connection, but will tell the client an available port. The client then uses this port to initiate a connection for file data transmission.
[0071] Specifically, first, the FTP server needs to be notified to specify the format of data transmission. In the FTP protocol, the FTP server can be requested to switch to binary mode by sending the "TYPE I" command. After receiving the request, the FTP server will confirm the switch to binary mode to ensure that the file data is transmitted in its original form. When the target file is ready to be downloaded, the FTP server is instructed to switch to the directory where the target file is located according to the obtained target file path. For example, the "CWD" command can be sent to the FTP server. Only when the correct working directory is entered can the FTP server find and prepare to download the specified file. During the file transfer process, the server is required to switch to passive mode, for example, the PASV command is sent to the FTP server. In passive mode, the FTP server waits for the client's connection on a specific port, and the client establishes a data transmission connection through the port. After entering the passive mode, the FTP server returns a port number and the download address of the target file to the client. The client uses this address and port number to establish a data connection with the FTP server to actually download the file.
[0072] In the present embodiment, first, by initiating a binary file type request and switching to binary mode, it is ensured that all files will not be converted or damaged during the transmission process, and the demand of different file types is adapted. Next, the working directory request is switched to ensure that the FTP server accurately locates the target file directory, and prepares for subsequent file downloads. Subsequently, the establishment of the data transmission connection can be controlled by initiating a passive mode request, and the firewall and port conflict problems that may occur when the FTP server actively establishes a connection are avoided. Finally, receiving the download address and port number enables the client to establish a stable data transmission connection with the FTP server through the specified port, and completes the efficient download of the file.
[0073] In one embodiment, after the step of establishing a data transmission connection with the FTP server according to the download address and the download port number, the method further includes:
[0074] Generate a permission request box according to the file information of the target file to request the user for permission to download the file;
[0075] When authorization is obtained, if it is determined that the file information of the target file contains sensitive information, the sensitive information is anonymized.
[0076] Among them, the file information of the target file refers to the metadata of the file, including the file name, size, type, creation time, modification time, etc., as well as sensitive information that may be involved, such as personal data, corporate data, etc. The permission request box is a user interface element used to request file download permissions from the user. In the Hongmeng system, it is usually a pop-up box containing file information and an authorization button, and the user needs to choose whether to allow the file to be downloaded. Sensitive information refers to content that may be contained in the file that needs to be protected, such as personal identity information, payment information, business secrets, etc. Anonymization refers to replacing or hiding the identifiable part of sensitive information so that the data can no longer point to a specific individual or entity. This processing can include operations such as removal, replacement, and encryption to ensure privacy and data security.
[0077] Specifically, when a user tries to download a target file, a permission request box is generated based on the file information. The request box contains basic information about the file, such as file name, size, type, etc., and prompts the user that the file may contain sensitive information, asking the user to confirm whether to allow the download. The Hongmeng system can generate the request box by calling the UI component, and limit the direct permission of the application to access the file through the sandbox mechanism to ensure that access rights are granted only after the user agrees. When the user views the file information and decides whether to allow the download, he can authorize or deny download permissions by clicking the "Agree" or "Reject" button.
[0078] If the user chooses to authorize, the file download process will continue. This authorization operation is usually controlled in the Hongmeng system by triggering the system permission management service to ensure that the application can only perform sensitive operations after obtaining explicit authorization from the user. Before downloading the file, the file information needs to be checked to determine whether it contains sensitive information. This can be done through content scanning or preset rules, such as matching certain data patterns or keywords, to ensure that the file does not violate the privacy protection policy during the download process. If the file information contains sensitive information, it will be anonymized before downloading. For example, depending on the file type and the type of sensitive information, personal information can be encrypted or replaced to ensure that user privacy is not leaked during data transmission. The Hongmeng system uses a sandbox mechanism to ensure that only applications authorized by the user can process this sensitive information.
[0079] In this embodiment, first, by generating a permission request box, it is ensured that the user is clearly informed before downloading the file and makes an authorization decision to prevent the application from unauthorized access to user data or improper operations. Next, the sensitive information in the file is detected and anonymized to ensure that even if data leakage occurs during the download process, the user's privacy information will not be exposed. Anonymization reduces the risk of information leakage by effectively shielding sensitive information and protects the sensitive data of users and enterprises from being abused. In the sandbox environment of the Hongmeng system, these operations are subject to strict permission restrictions, and only applications authorized by the user can perform these sensitive operations, thereby ensuring the security of the system and data privacy.
[0080] In one embodiment, the step of downloading the target file through the worker multi-thread of the Hongmeng system includes:
[0081] Create a worker multithreaded program in Hongmeng system to manage the download queue, which contains a list of target files.
[0082] In worker multithreading, a polling mechanism is used to download the target file.
[0083] The download queue is a data structure that stores a list of target files to be downloaded. Each file has its corresponding download task. The queue is arranged in a certain order and is responsible for managing and controlling the download process of the file. The polling mechanism refers to traversing the target files in the download queue in order, taking out one file at a time for processing until all files in the queue are processed.
[0084] Specifically, in the Hongmeng system, multiple threads can be created through the multitasking module, and each thread is used to download a target file in the queue. When creating, an independent execution environment can be assigned to each thread to ensure that they can run in parallel without interfering with each other. As a queue data structure, the download queue can be maintained by the queue management module inside the Hongmeng system. The queue stores all target files to be downloaded and queues them according to certain rules. When managing the queue, you can add, delete or query elements in the queue, that is, files to be downloaded, and use the scheduling algorithm to ensure that the download task of each file is executed.
[0085] In the worker thread, the polling mechanism is used to sequentially access the target files in the download queue. Each worker thread will take the next file from the queue and perform the download operation. After the download is completed, the worker thread will continue to process the next file until all files in the queue are downloaded. The polling mechanism ensures the order of file downloads and avoids resource competition between threads.
[0086] In this embodiment, by creating worker multithreading and managing the download queue in the Hongmeng system, the concurrency and processing efficiency of the file download task can be effectively improved. First, worker multithreading can handle multiple download tasks at the same time, reducing the waiting time during the download process and increasing the overall speed of file downloads. By allocating files in the download queue to different threads, the Hongmeng system can maximize the computing power of multi-core processors to ensure the parallel execution of download tasks. Secondly, using a polling mechanism to download files ensures that each file is processed evenly. The polling mechanism processes files in sequence, avoiding performance bottlenecks caused by too many threads competing for the same resource. Each thread only processes one file in the queue, avoiding conflicts and blocking between threads and improving the stability of the download process.
[0087] Based on this, the parallelism of file downloads is improved, making full use of the Hongmeng system's optimization of multi-core processing, which is especially suitable for scenarios where multiple files need to be downloaded. Secondly, the polling mechanism enables file download tasks to be carried out in sequence, ensuring that each file in the queue can be processed in a timely manner, avoiding confusion in task scheduling. This efficient and stable download method can not only speed up file transfers, but also ensure the reasonable allocation of system resources, ultimately improving the overall download experience and system resource utilization efficiency.
[0088] In one embodiment, the method further comprises:
[0089] If the target file is a large file, use the file system API of Hongmeng system in read-write mode to open the local storage folder used to store the downloaded file;
[0090] When each data packet of the target file sent by the FTP server is received, the file writing method is called to write the received data packet to the end of the storage folder.
[0091] Among them, the file system API of the Hongmeng system: The file system API of the Hongmeng system provides a set of interfaces that allow applications to store, read and operate files locally. These APIs enable applications to read and write data in the form of files by abstracting the underlying file system of the operating system. Data packets are file fragments divided into a certain size in file transfer. When transmitting files over the network, the file is usually divided into multiple data packets for transmission. Each data packet contains part of the data of the file. The receiver receives and reassembles these data packets to complete the reconstruction of the file.
[0092] Specifically, when the target file is a large file, the FTP server will send data packets in batches. Based on this, in the Hongmeng system, opening the storage folder can be done through the file system API. Specifically, according to the specified path, opening the folder in read-write mode means being ready to write file data in the storage folder. For example, first get the folder path, then verify the existence of the folder, and then open the folder through the file system API for subsequent read and write operations.
[0093] When the FTP server sends a data packet to the client, the network module of the Hongmeng system receives the data packet and writes the content of the data packet to the target file through the file system API. The file writing method locates to the end of the file according to the current position of the target file, and then appends each received data packet to write in sequence. In this way, the file data continues to extend at the end of the file until all data packets are transferred. For the transmission of large files, the file content is dynamically updated to ensure the order and integrity of the file. In an example, using the API provided by the Hongmeng system, the fs.write method is used and the parameter Options is set to OpenMode.READ_WRITE to ensure that each received data packet is correctly appended to the end of the file, thereby ensuring the integrity of large file downloads.
[0094] In this embodiment, first, the local storage folder is opened and set to read-write mode to ensure that the local device can accept and save large files from the FTP server. Through the file system API of the Hongmeng system, reliable support can be provided for file operations to ensure that the folder exists and data can be written. Opening the folder in read-write mode can ensure that during the download process, not only can the file be read, but also new data can be written to the file. Secondly, when each data packet sent by the FTP server is received, the file writing method is called to append the data packet to the end of the local file in order to efficiently handle the block download of large files. By receiving and writing data in blocks, excessive memory occupation and delays in the transmission process are avoided. After each write operation, the file is always in an available state, ensuring that the file data will not be lost, while avoiding the rewriting of the entire file, thereby improving the efficiency of file transmission. Finally, by writing the data packet to the end of the storage folder in sequence, the integrity and correctness of the downloaded file can be ensured. Since the files are appended in the order of data packets, it can be ensured that the target file is completely consistent with the structure of the original file after the transmission is completed, avoiding data errors or losses.
[0095] The efficient file system API of Hongmeng system can efficiently manage the data writing operation in the process of large file download. In the process of file download, not only the order and integrity of file data are guaranteed, but also the memory usage and file transfer efficiency are optimized by writing each data packet in real time, which ultimately improves the performance and stability in the large file download scenario.
[0096] In one embodiment, the method further comprises:
[0097] Use the API set for network communication in the Hongmeng system to connect to the network.
[0098] Among them, the network communication API set in the Hongmeng system refers to a set of interfaces that allow applications to communicate over the network on the Hongmeng operating system. They provide support for various network protocols, such as TCP / IP, HTTP, FTP, etc., for data transmission and connection between devices. These APIs are bridges for information exchange between applications and external services or devices in the Hongmeng system. For example, use the classes in the ohos.net package to handle network connections to ensure compatibility on the Hongmeng system.
[0099] In this embodiment, the network communication API in the Hongmeng system is used for network connection. First, the connection is initialized by selecting the appropriate protocol and network interface, laying the foundation for data exchange between the computer device and the FTP server. By calling these APIs, a connection request can be initiated and a response can be waited for according to the target address and protocol type to ensure the reliability of data transmission. When the connection is successful, data transmission can be started with the FTP server to ensure the smooth exchange of information. Through this process, the Hongmeng system provides a flexible and efficient network connection mechanism to ensure stability and compatibility in different network environments. At the same time, these APIs support various common network protocols and data transmission methods, and can select the most appropriate connection method according to needs.
[0100] To facilitate understanding of the solution of the present application, specific examples are provided below for illustration.
[0101] like Figure 2 As shown, the Hongmeng system application downloads files on the FTP server based on the TCP / IP protocol:
[0102] ① Enter the server address and negotiate with the server to set the default port number to 21. Click the "Synchronize" button on the Hongmeng application software. The TCP protocol layer will establish a connection with the server. After the connection is successful, the response packet will be: 220 Welcome to vsftpd service;
[0103] ②After receiving the 220 response, the TCP protocol layer request for the username is initiated again, and the default is root; the response packet at this time is: 331 Please specify the password;
[0104] ③After receiving the 331 response, the password TCP protocol layer request is initiated again. The response packet is: 230 Loginsuccessful;
[0105] ④ After receiving the 230 response, it indicates that the login with the server has been successful. Then, a binary file type TCP protocol layer request is initiated again to inform the server that the file currently to be downloaded is of binary type. At this time, the response packet is: 200 Switching to Binary mode;
[0106] ⑤ After receiving the 200 response, it indicates that the mode has been switched to binary mode. The TCP protocol layer request to switch the working directory is initiated again. The working directory to be switched is the directory where the downloaded file is located. This is the working directory negotiated with the server, for example: server address: port number / working directory / Test / ... At this time, the response packet is: 250 Directory successfully changed;
[0107] ⑥After receiving the 250 response, it indicates that the working directory has been successfully switched. The passive mode TCP protocol layer request is initiated again. The response packet is: 227 Entering Passive Mode (192, 168, 1, 238, 217, 191);
[0108] ⑦ After receiving the 227 response, it indicates the address and port number of the downloaded file. At this time, it is necessary to create a new TCP Socket to establish a new link with the currently informed address and port number. This is the data packet address and port number for file download. Initiate a TCP protocol layer request for the file name again to download the corresponding file. At this time, after the server receives the request for the specified file name, it sends the file stream data to the client, and the current download ends!
[0109] The following is a description of the FTP file download device based on the Hongmeng system provided in the embodiment of the present application. The FTP file download device based on the Hongmeng system described below and the FTP file download method based on the Hongmeng system described above can be referred to each other. Figure 3 As shown, the present application also provides an FTP file downloading device based on the Hongmeng system, the device comprising:
[0110] The FTP server login module 201 is used to, in the sandbox of the Hongmeng system, respond to the FTP synchronization request, obtain the login information of the FTP server from the FTP synchronization request, and use the login information to log in to the FTP server;
[0111] The download address acquisition module 202 is used to instruct the FTP server to switch to binary mode after successfully logging into the FTP server, instruct the FTP server to enter the target file directory according to the acquired target file directory, and receive the download address and download port number of the target file returned by the FTP server;
[0112] The target file download module 203 is used to establish a data transmission connection with the FTP server according to the download address and download port number, and download the target file through the worker multi-threading of the Hongmeng system. When the target file is downloaded, the data transmission connection is closed.
[0113] In one embodiment, the login information includes the FTP server IP address, the FTP server port number, the user name and its corresponding password; the FTP server login module 201 includes:
[0114] A connection request initiating unit, used to initiate a connection request to the FTP server according to the FTP server IP address and the FTP server port number;
[0115] A user name request initiating unit, for initiating a user name request to the FTP server according to the user name when it is determined that the connection with the FTP server is successful, so that the FTP server verifies the user name;
[0116] The FTP server login unit is used to initiate a password request to the FTP server according to the password corresponding to the username when it is determined that the username verification has passed, so that the FTP server verifies the password, and when it is determined that the password verification has passed, confirm the login to the FTP server.
[0117] In one embodiment, the download address acquisition module 202 includes:
[0118] A binary file type request initiating unit, used for initiating a binary file type request to the FTP server, so that the FTP server switches to a binary mode;
[0119] A working directory switching request initiating unit, configured to initiate a working directory switching request to the FTP server according to the acquired target file directory when it is determined that the FTP server is switched to the binary mode, so that the FTP server switches to the target file directory;
[0120] The download address acquisition unit is used to initiate a passive mode request to the FTP server when it is determined that the FTP server enters the target file directory, and receive the download address and download port number of the target file returned by the FTP server.
[0121] In one embodiment, after the target file download module 203, the following is further included:
[0122] A permission request box generation module is used to generate a permission request box according to the file information of the target file to request the user for file download permission;
[0123] The anonymization processing module is used to anonymize the sensitive information if it is determined that the file information of the target file contains sensitive information when authorization is obtained.
[0124] In one embodiment, the target file download module 203 includes:
[0125] A multi-thread creation unit, used to create worker multi-threads in the Hongmeng system for managing a download queue, where the download queue contains a file list of target files;
[0126] The target file download unit is used to download the target file using a polling mechanism in worker multi-threading.
[0127] In one embodiment, the apparatus further comprises:
[0128] The storage folder opening module is used to use the file system API of the Hongmeng system in read-write mode to open the local storage folder for storing downloaded files if the target file is a large file;
[0129] The data packet writing module is used to call the file writing method when receiving each data packet of the target file sent by the FTP server, and write the received data packet to the end of the storage folder.
[0130] In one embodiment, the apparatus further comprises:
[0131] The network connection module is used to connect to the network using the API set for network communication in the Hongmeng system.
[0132] In one embodiment, the present application also provides a storage medium, which stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the FTP file download method based on the Hongmeng system as described in any of the above embodiments.
[0133] In one embodiment, the present application also provides a computer device, which stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the FTP file download method based on the Hongmeng system as described in any of the above embodiments.
[0134] Indicatively, Figure 4 As shown, Figure 4This is a schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. The computer device 300 may be provided as a server. Figure 4 , the computer device 300 includes a processing component 302, which further includes one or more processors, and a memory resource represented by a memory 301, for storing instructions executable by the processing component 302, such as an application. The application stored in the memory 301 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 302 is configured to execute instructions to execute the FTP file download method based on the Hongmeng system of any of the above embodiments.
[0135] The computer device 300 may further include a power supply component 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 may operate based on an operating system stored in the memory 301, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM, or the like.
[0136] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0137] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the elements. Herein, "one", "one", "said", "the" and "it" may also include plural forms, unless the context clearly indicates another way. A plurality refers to at least two cases, such as 2, 3, 5 or 8, etc. "And / or" includes any and all combinations of the relevant listed items.
[0138] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0139] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A FTP file download method based on Hongmeng system, characterized in that: The method comprises: In the sandbox of the Hongmeng system, in response to an FTP synchronization request, obtaining login information of an FTP server from the FTP synchronization request, and using the login information to log in to the FTP server; When the FTP server is successfully logged in, the FTP server is instructed to switch to binary mode, and then, according to the acquired target file directory, the FTP server is instructed to enter the target file directory, and the download address and download port number of the target file returned by the FTP server are received; According to the download address and the download port number, a data transmission connection is established with the FTP server, and the target file is downloaded through the worker multi-threading of the Hongmeng system. When the download of the target file is completed, the data transmission connection is closed.
2. According to the FTP file download method based on Hongmeng system according to claim 1, it is characterized in that: The login information includes an FTP server IP address, an FTP server port number, a user name and a corresponding password; the step of using the login information to log in to the FTP server includes: Initiate a connection request to the FTP server according to the FTP server IP address and the FTP server port number; When it is determined that the connection with the FTP server is successful, initiating a username request to the FTP server according to the username, so that the FTP server verifies the username; When it is determined that the username verification is passed, a password request is initiated to the FTP server according to the password corresponding to the username, so that the FTP server verifies the password, and when it is determined that the password verification is passed, the login to the FTP server is confirmed.
3. The FTP file download method based on Hongmeng system according to claim 1 is characterized in that: After instructing the FTP server to switch to binary mode, according to the acquired target file directory, instructing the FTP server to enter the target file directory, and receiving the download address and download port number of the target file returned by the FTP server, the step includes: Initiate a binary file type request to the FTP server to switch the FTP server to binary mode; When it is determined that the FTP server is switched to binary mode, a working directory switching request is initiated to the FTP server according to the acquired target file directory, so that the FTP server switches to the target file directory; When it is determined that the FTP server enters the target file directory, a passive mode request is initiated to the FTP server, and a download address and a download port number of the target file returned by the FTP server are received.
4. The FTP file download method based on Hongmeng system according to claim 1 is characterized in that: After the step of establishing a data transmission connection with the FTP server according to the download address and the download port number, the method further includes: Generate a permission request box according to the file information of the target file to request the user for file download permission; When obtaining authorization, if it is determined that the file information of the target file contains sensitive information, the sensitive information is anonymized.
5. The FTP file download method based on Hongmeng system according to claim 1 is characterized in that: The step of downloading the target file through worker multi-threading of the Hongmeng system includes: Creating worker multithreading in the Hongmeng system for managing a download queue, wherein the download queue contains a file list of the target file; In the worker multithreading, a polling mechanism is adopted to download the target file.
6. The FTP file download method based on Hongmeng system according to claim 1 is characterized in that: The method further comprises: If the target file is a large file, the file system API of the Hongmeng system is used to open the local storage folder for storing the downloaded file in read-write mode; When each data packet of the target file sent by the FTP server is received, a file writing method is called to write the received data packet to the end of the storage folder.
7. The FTP file download method based on Hongmeng system according to any one of claims 1 to 6 is characterized in that: The method further comprises: Use the API set for network communication in the Hongmeng system to establish a network connection.
8. An FTP file downloading device based on Hongmeng system, characterized in that: The device comprises: An FTP server login module is used to, in the sandbox of the Hongmeng system, in response to an FTP synchronization request, obtain login information of the FTP server from the FTP synchronization request, and use the login information to log in to the FTP server; A download address acquisition module is used to instruct the FTP server to switch to binary mode after successfully logging into the FTP server, instruct the FTP server to enter the target file directory according to the acquired target file directory, and receive the download address and download port number of the target file returned by the FTP server; The target file download module is used to establish a data transmission connection with the FTP server according to the download address and the download port number, and download the target file through the worker multi-threading of the Hongmeng system. When the download of the target file is completed, the data transmission connection is closed.
9. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the FTP file download method based on the Hongmeng system as described in any one of claims 1 to 7.
10. A computer device, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the FTP file download method based on the Hongmeng system as described in any one of claims 1 to 7 are performed.
Citation Information
Patent Citations
Method and system for downloading software
CN101848108A
Method for achieving multithreading breakpoint upload of oversized file based on FTP
CN103442037A
FTP server and file transmission method
CN105338121A
Security file ferrying system
CN113794777A
File transfer protocol test method and device, computer equipment and storage medium
CN116248564A