FTP file download method, device and storage medium based on Hongmeng system

By obtaining the login information of the FTP server in the HarmonyOS sandbox and switching to binary mode, and using worker multi-threading to download files, the problem of the lack of FTP support in the HarmonyOS is solved, efficient FTP file transfer is achieved, and the system's functionality and compatibility are enhanced.

CN119697178BActive Publication Date: 2025-09-09广州市迪士普音响科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510117165.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-09-09
Estimated Expiration
2045-01-24

AI Technical Summary

Technical Problem

The lack of direct FTP support in the HarmonyOS makes it difficult to implement the FTP file download function, which requires additional time and effort to adapt, and the compatibility of third-party FTP libraries is uncertain.

Method used

Respond to FTP synchronization requests in the sandbox of the Hongmeng system, obtain and use the login information of the FTP server, switch to binary mode, obtain the download address and port number of the target file, and download the file through worker multi-threading. After the download is complete, close the connection.

Benefits of technology

It provides a stable FTP file download solution, realizes efficient file transfer, and enhances the functionality and compatibility of the Hongmeng system in the field of file transfer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119697178B_ABST
    Figure CN119697178B_ABST
Patent Text Reader

Abstract

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 Hongmeng system's lack of direct FTP support, provides a stable FTP file download solution, effectively realizes the efficient transmission of FTP files, and enhances the functionality and compatibility of the Hongmeng system in the field of file transfer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an FTP file download method, device and storage medium based on the Hongmeng system. Background Art

[0002] In today's digital age, operating systems, as the core link between users and devices, are crucial for their rich and comprehensive functionality. As an emerging operating system, HarmonyOS, with its rich APIs and development tools, as well as support for multiple network communication protocols, provides developers with an efficient application development environment, empowering the creation of a wide range of innovative applications. However, in the critical area of ​​network file transfer, HarmonyOS currently lacks direct FTP support, nor does it officially offer dedicated FTP-related APIs. This prevents developers from leveraging native system resources when implementing FTP file download functionality. In stark contrast, Android, with its mature ecosystem and open capabilities, has fostered widely used and well-proven third-party FTP libraries such as Apache Commons Net, which can reliably meet FTP operation requirements. However, HarmonyOS's lack of direct support for the FTP protocol, coupled with uncertain compatibility with third-party FTP libraries, has limited the implementation of FTP file download functionality on the HarmonyOS platform, requiring additional time and effort for adaptation. 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 existing technology that limit the implementation of FTP file download function on the Harmony 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, obtaining the login information of the FTP server from the FTP synchronization request, and logging into the FTP server using the login information;

[0006] After successfully logging into the FTP server, the FTP server is instructed to switch to binary mode. Then, based on the target file directory obtained, the FTP server is instructed to enter the target file directory and receive the download address and download port number of the target file returned by the FTP server.

[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 the connection with the FTP server is confirmed to be successful, a username request is sent to the FTP server based on 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 sent to the FTP server based on the password corresponding to the username, so that the FTP server verifies the password. When it is determined that the password verification is successful, the user confirms logging into the FTP server.

[0012] In one embodiment, after instructing the FTP server to switch to binary mode, the steps of instructing the FTP server to enter the target file directory based on the acquired target file directory, and receiving the download address and download port number of the target file returned by the FTP server 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 has switched to binary mode, a working directory switching request is sent to the FTP server according to the obtained 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 the FTP server according to the download address and the download port number, the method further includes:

[0017] Generate a permission request box based on the file information of the target file to request the user for file download permission;

[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 steps of downloading the target file through the worker multi-threading of the Hongmeng system include:

[0020] Create a worker multithreaded program in Hongmeng OS to manage the download queue, which contains a list of target files.

[0021] In worker multi-threading, 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 Hongmeng system's file system API 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 download device based on the Hongmeng system, the device comprising:

[0028] An FTP server login module, configured to, in the Hongmeng system sandbox, 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 based on 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 based on 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 download is completed, the data transmission connection is closed.

[0031] In a 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 Harmony system as described in any one 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 Harmony system in any of the above 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 Hongmeng system's lack of direct FTP support, provides a stable FTP file download solution, effectively realizes the efficient transmission of FTP files, and enhances the functionality 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 following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 any creative labor.

[0037] Figure 1 A flowchart of the FTP file download method based on the Hongmeng system provided in an embodiment of the present application;

[0038] Figure 2 An example diagram of the 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 this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0042] This application provides an FTP file download method based on the Hongmeng system. The following embodiments are explained by taking the method applied to a computer device 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 HarmonyOS is a virtualized isolation environment used to run and manage applications, ensuring that applications are executed in a safe isolated space, thereby avoiding affecting other parts of the system and enhancing the security and stability of the operating system. An FTP synchronization request is a request issued by the client to establish a connection with the FTP server and perform a file transfer operation, 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, the FTP synchronization request from the client is responded to. When the client initiates the request, the request signal is received and processed accordingly based on the content of the request to ensure that the subsequent steps can proceed smoothly. Next, the login information of the FTP server is obtained from the request, which may include the user name and password, to ensure a successful connection and interaction with the FTP server. This information is extracted and prepared for use in identity verification and connection establishment. Subsequently, the obtained login information is used to log in to the FTP server, which can be by sending the user name and password to the FTP server and waiting for the return of the FTP server's verification information. If the verification is successful, the connection with the FTP server is established, and preparations are made for subsequent data transmission.

[0046] It's understandable that within the HarmonyOS sandbox, responding to FTP synchronization requests and obtaining the FTP server's login information ensures proper communication between the HarmonyOS and the FTP server. Through the sandbox mechanism, the HarmonyOS isolates applications and limits their access to system resources and files. This allows applications to obtain FTP server login information and complete login operations within the sandbox only if explicitly authorized. This isolation mechanism effectively prevents unauthorized access to sensitive data, reducing 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, thus achieving secure and efficient file transfer. Because the sandbox provides additional security protection, the HarmonyOS system can provide a more stable and controlled communication channel while ensuring data privacy. The sandbox not only protects the HarmonyOS 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 unauthorized access while providing a reliable foundation for subsequent data transfer operations.

[0048] S102: After successfully logging into the FTP server, the FTP server is instructed to switch to binary mode. Then, according to the acquired target file directory, the FTP server is instructed to enter the target file directory and receive the download address and download port number of the target file returned by the FTP server.

[0049] Binary mode is a data transmission mode in the FTP protocol, suitable for transferring non-text files such as images, videos, and audio. Binary mode ensures that files are not modified or any data is lost during transmission. The target file directory refers to the specific path where the target file is stored on the FTP server. During the file download process, it is necessary to instruct the FTP server to enter this 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 and 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 errors or content loss occur 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 1" command to ensure that the file keeps the original data unchanged during the transmission process. Next, because the files are stored in a specific directory, if the correct directory is not switched to, the target file cannot be found. In one 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 carry out data transmission with the FTP server. In this way, a stable connection with the FTP server and efficient file transfer can be ensured, and the file transfer failure caused by format mismatch or directory error can be avoided, thereby improving the reliability and efficiency of the whole file download process.

[0051] As you can understand, first, instructing the FTP server to switch to binary mode ensures the integrity of the file data, preventing data corruption or loss during transmission. Next, by instructing the FTP server to enter the target file directory, the path to the stored file can be accurately located. Finally, by receiving the download address and port number returned by the FTP server, a data transfer connection can be accurately established, ensuring that the file can be downloaded from the FTP server to the local computer 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 target file is downloaded, close the data transmission connection.

[0053] The data transmission connection refers to the network connection established with the FTP server, through which the actual file transfer is performed, including uploading, downloading, or deleting files. Worker multithreading is a mechanism in the HarmonyOS 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 break down the download task into multiple threads, thereby accelerating 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 Harmony 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 is understandable 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 Harmony 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 Harmony 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 HarmonyOS's worker multi-threading technology, multiple threads can be started at the same time to download the target file in parallel. HarmonyOS supports multi-tasking parallel processing, fully utilizing 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 download speed and reduce waiting time. The efficient scheduling mechanism of HarmonyOS 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 complete, closing the data transfer connection frees up network and system resources, avoiding unnecessary resource waste caused by maintaining a connection for a long time. HarmonyOS's resource management mechanism automatically cleans up related network and memory resources when closing a connection, ensuring that system resources are utilized rationally and avoiding system overload. This not only improves the stability and efficiency of file downloads, but also ensures 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 system switches to binary mode, obtains the download address and port of the target file, and establishes 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 complete. This method solves the problem of the Hongmeng system's lack of direct FTP support, provides a stable FTP file download solution, effectively realizes the efficient transmission of FTP files, and enhances the functionality 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. 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 the connection with the FTP server is confirmed to be successful, a username request is sent to the FTP server based on 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 sent to the FTP server based on the password corresponding to the username, so that the FTP server verifies the password. When it is determined that the password verification is successful, the user confirms logging into the FTP server.

[0063] The FTP server IP address is a unique identifier for the FTP server on the network and 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 on which the FTP service listens and receives connection requests. FTP typically uses port 21 by default for control connections. The username is an identifier registered on the FTP server that identifies the user. Each FTP account has a unique username. The password is authentication information used in conjunction with the username to ensure that only authorized users can access resources on the FTP server. A connection request is a request sent to the FTP server to establish a network connection. It typically includes the FTP server's IP address and port number, specifying the target device to communicate with the FTP server. A username request is a request sent to the FTP server to inform the FTP server of the username to be provided. The FTP server then verifies the validity of the username. A password request is a request sent by the client to the FTP server, providing the password corresponding to the username. The FTP server verifies the password and decides whether to grant access.

[0064] Specifically, a connection request must first be sent to the FTP server, specifying the server's IP address and port number, and attempting to establish a connection using the TCP / IP protocol. When the request, including the FTP server's IP and port information, is sent, the FTP server receives it and waits for a response. If the connection request is successful, a data transmission channel is established with the FTP server. After the connection is established, a request containing a username must be sent to the FTP server, informing the FTP server of the username information to be provided. Upon receiving the username request, the FTP server verifies the username against its stored user data to verify its existence and validity. If the username is successfully verified, the FTP server sends the password corresponding to the username to the FTP server. The FTP server then verifies the password by comparing it with the password stored in its database. Once the FTP server verifies that both the username and password are correct, it confirms the login is successful, indicating that the FTP server has authorized the client to access its resources, and the two parties can begin further data exchange.

[0065] In this embodiment, initiating a connection request to the FTP server ensures that the client can correctly find and connect to the FTP server. The subsequent username and password verification process is designed to protect FTP server resources and prevent unauthorized access. By sequentially sending username and password requests to the FTP server, the client's identity is gradually confirmed. Only after the username and password are verified can the client be granted access rights. This ensures the security and accuracy of file transfer operations, prevents intrusion by unauthorized users, and ensures that only correct authentication information is passed, reducing the risk of data leakage.

[0066] In one embodiment, after instructing the FTP server to switch to binary mode, the steps of instructing the FTP server to enter the target file directory based on the acquired target file directory, and receiving the download address and download port number of the target file returned by the FTP server 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 has switched to binary mode, a working directory switching request is sent to the FTP server according to the obtained 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] A binary file type request is a command sent to the FTP server via the FTP protocol, requesting the server to use binary mode to transfer files. Binary mode ensures that file data remains unchanged during transfer and is applicable to all file types. A change working directory request is a command sent to the FTP server via the FTP protocol, requesting the server to switch to the directory where the target file is located. A passive mode request requests the FTP server to enter passive mode. In this mode, the FTP server does not actively open a data connection. Instead, it notifies the client of an available port, which the client then uses to initiate a connection for file data transfer.

[0071] Specifically, the FTP server must first be notified of the data transmission format. In the FTP protocol, the "TYPE I" command can be sent to request that the FTP server switch to binary mode. Upon receiving this request, the FTP server confirms 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 containing the target file based on the obtained target file path. For example, the "CWD" command can be sent to the FTP server. Only by entering the correct working directory can the FTP server locate and prepare to download the specified file. During the file transfer process, the server is requested to switch to passive mode, for example, by sending the PASV command to the FTP server. In passive mode, the FTP server waits for a client connection on a specific port, and the client establishes a data transfer connection through this port. After entering 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 and 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, thereby adapting to the needs of different file types. Next, switching the working directory request ensures that the FTP server accurately locates the target file directory and prepares for subsequent file downloads. Subsequently, initiating a passive mode request can control the establishment of the data transmission connection, thereby avoiding the firewall and port conflict problems that may occur when the FTP server actively establishes a connection. 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, thereby completing the efficient download of files.

[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 based on the file information of the target file to request the user for file download permission;

[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 permission from the user. In the Harmony 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 processing 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 attempts to download a target file, a permission request box is generated based on the file information. This 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 this request box by calling UI components and limit the application's direct access to files 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 or she 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 Harmony 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 Harmony 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 accessing user data or performing improper operations without authorization. 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 private information will not be exposed. Anonymization reduces the risk of information leakage by effectively masking 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. 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 steps of downloading the target file through the worker multi-threading of the Hongmeng system include:

[0081] Create a worker multithreaded program in Hongmeng OS to manage the download queue, which contains a list of target files.

[0082] In worker multi-threading, 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 a corresponding download task. The queue is arranged in a specific order and is responsible for managing and controlling the file download process. A round-robin mechanism sequentially iterates through the target files in the download queue, removing each file for processing one at a time until all files in the queue have been processed.

[0084] Specifically, in the Harmony system, multiple threads can be created through the multi-tasking 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. The download queue, as a queue data structure, can be maintained by the queue management module within the Harmony 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 worker threads, a round-robin mechanism is used to sequentially access target files in the download queue. Each worker thread retrieves the next file from the queue and downloads it. After the download is complete, the worker thread moves on to the next file until all files in the queue have been downloaded. This round-robin mechanism ensures sequential file downloads and avoids resource contention 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, the worker multithreading can handle multiple download tasks at the same time, reducing the waiting time during the download process and improving 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 the multi-core processor and ensure the parallel execution of download tasks. Secondly, using a polling mechanism to download files can ensure 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 resources. Each thread only processes one file in the queue, avoiding conflicts and blockages between threads and improving the stability of the download process.

[0087] Based on this, the parallelism of file downloads is improved, fully utilizing the Hongmeng system's optimization for multi-core processing, which is particularly suitable for scenarios that require downloading multiple files. Secondly, the polling mechanism allows file download tasks to proceed in sequence, ensuring that every file in the queue is processed in a timely manner and avoiding task scheduling confusion. This efficient and stable download method not only accelerates file transfers, but also ensures the rational 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 Hongmeng system's file system API 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 Harmony system: The file system API of the Harmony system provides a set of interfaces that allow applications to store, read, and operate files locally. These APIs abstract the underlying file system of the operating system, allowing applications to read and write data in the form of files. Data packets are file fragments divided into a certain size in file transfer. When transferring files over the network, the file is usually divided into multiple data packets for transmission. Each data packet contains part of the file data. The recipient 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 obtain 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 Harmony system receives the data packet and writes the contents of the data packet to the target file through the file system API. The file writing method will locate the end of the file based on the current position of the target file, and then append each received data packet to it in sequence. In this way, the file data will continue to expand at the end of the file until all data packets are transferred. For the transmission of large files, the file content will be dynamically updated to ensure the order and integrity of the file. In an example, the API provided by the Harmony system is used, through the fs.write method and setting the parameter Options 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 receive and save large files from the FTP server. The HarmonyOS file system API provides reliable support for file operations, ensuring that the folder exists and data can be written. Opening the folder in read-write mode ensures that files can be read and written to during the download process. Secondly, when each data packet sent by the FTP server is received, the file write method is called to append the data packet to the end of the local file. This allows for efficient processing of the multi-block download of large files. By receiving and writing data in blocks, excessive memory usage and delays during the transmission process are avoided. After each write operation, the file is always available, ensuring that file data is not lost and avoiding the need to rewrite the entire file, thereby improving file transfer efficiency. Finally, by writing data packets sequentially to the end of the storage folder, the integrity and correctness of the downloaded file are ensured. Because files are appended in packet order, the target file is guaranteed to fully conform to the original file structure after the transfer is complete, avoiding data errors or loss.

[0095] HarmonyOS's efficient file system API effectively manages data write operations during large file downloads. This not only ensures the sequentiality and integrity of file data during the download process, but also optimizes memory usage and file transfer efficiency by writing each data packet in real time, ultimately improving performance and stability in large file download scenarios.

[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] The network communication API collection in HarmonyOS refers to a set of interfaces that allow applications to communicate over the network on the HarmonyOS 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 serve as a bridge for information exchange between applications in the HarmonyOS system and external services or devices. For example, classes in the ohos.net package are used to handle network connections to ensure compatibility on the HarmonyOS system.

[0099] In this embodiment, the network communication API in the Harmony system is used to connect to the network. 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 based on the target address and protocol type, ensuring 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 Harmony system provides a flexible and efficient network connection mechanism, ensuring stability and compatibility in different network environments. At the same time, these APIs support a variety of common network protocols and data transmission methods, and can select the most appropriate connection method according to needs.

[0100] To facilitate understanding of the solutions of this 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 username 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 at this time is: 230 Login successful;

[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 to be downloaded is of binary type. The response packet is: 200 Switching to Binary mode;

[0106] ⑤ After receiving the 200 response, indicating that the mode has been switched to binary mode, the TCP protocol layer request to switch the working directory is initiated again. The switching working directory 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 / ... The response packet at this time is: 250 Directory successfully changed;

[0107] ⑥ After receiving the 250 response, indicating that the working directory has been successfully switched, the passive mode TCP protocol layer request is initiated again, and the response packet is: 227 Entering Passive Mode (192, 168, 1, 238, 217, 191);

[0108] ⑦ After receiving the 227 response, indicating the address and port number for the file to be downloaded, a new TCP socket is created to establish a new connection with the currently informed address and port number. This is the address and port number for the data packet download. Another TCP protocol layer request for the file name is initiated to download the corresponding file. After receiving the request for the specified file name, the server sends the file stream data to the client, and the current download is completed!

[0109] The following describes 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 refer to each other. Figure 3 As shown, the present application also provides an FTP file download 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 log in to the FTP server using the login information;

[0111] The download address acquisition module 202 is used to, upon successful login to the FTP server, instruct the FTP server to switch to binary mode, instruct the FTP server to enter the target file directory based on 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 based on 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 download is completed, 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, configured 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 is used to initiate a user name request to the FTP server based on the user name when determining 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 is passed, so that the FTP server verifies the password, and confirms logging into the FTP server when it is determined that the password verification is passed.

[0117] In one embodiment, the download address acquisition module 202 includes:

[0118] A binary file type request initiating unit, configured to initiate 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, when determining that the FTP server has switched to binary mode, initiate a working directory switching request to the FTP server based on the acquired target file directory, 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 the download queue, which contains a file list of the target file;

[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 Harmony system.

[0132] In one embodiment, the present application also provides a storage medium storing 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 Harmony system as described in any of the above embodiments.

[0133] In one embodiment, the present application also provides a computer device having computer-readable instructions stored therein. 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 Harmony system as described in any of the above embodiments.

[0134] Schematically, as 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 can 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 perform 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™, Mac OS X™, Unix™, Linux™, Free BSD™, 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 shown in the figure, or combine certain components, or have a different component arrangement.

[0137] Finally, it should be noted that, in this article, relational terms such as first and second are merely used to distinguish one entity or operation from another, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprise," "include," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. Without further restriction, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element. Herein, "one," "said," "the," and "its" may also include plural forms unless the context clearly indicates otherwise. A plurality refers to at least two, such as 2, 3, 5, or 8. "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 be referenced to each other.

[0139] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one 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 is not limited to the embodiments shown herein, but is intended to 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 the FTP synchronization request, obtaining login information of the FTP server from the FTP synchronization request, and logging into the FTP server using the login information; When the FTP server is successfully logged in, the FTP server is instructed to switch to binary mode, and then, based on 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 a permission request box is generated according to the file information of the target file to request file download permission from the user. When authorization is obtained, if it is determined that the file information of the target file contains sensitive information, the sensitive information is anonymized, 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. The FTP file download method based on the Hongmeng system according to claim 1 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; and the step of logging into the FTP server using the login information 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 the Hongmeng system according to claim 1 is characterized in that: After instructing the FTP server to switch to binary mode, the steps of instructing the FTP server to enter the target file directory according to the acquired target file directory, and receiving the download address and download port number of the target file returned by the FTP server include: Initiating a binary file type request to the FTP server, so that the FTP server switches 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 has entered 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 the Hongmeng system according to claim 1 is characterized in that: The step of downloading the target file through the worker multi-thread of the Hongmeng system includes: Creating a worker multithread for managing a download queue in the Hongmeng system, wherein the download queue includes a file list of the target file; In the worker multi-thread, a polling mechanism is adopted to download the target file.

5. The FTP file download method based on the 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.

6. The FTP file download method based on the Hongmeng system according to any one of claims 1 to 5, characterized in that: The method further comprises: Use the API set for network communication in the Hongmeng system to establish a network connection.

7. An FTP file downloading device based on Hongmeng system, characterized in that: The device comprises: An FTP server login module is configured to, in the sandbox of the Hongmeng system, respond to an FTP synchronization request, obtain login information of the FTP server from the FTP synchronization request, and log in to the FTP server using the login information; a download address acquisition module, configured to, upon successful login to the FTP server, instruct the FTP server to switch to binary mode, instruct the FTP server to enter the target file directory based on 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, generate a permission request box according to the file information of the target file, and request file download permission from the user. When authorization is obtained, if it is determined that the file information of the target file contains sensitive information, the sensitive information is anonymized, 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.

8. A storage medium, characterized in that: The storage medium stores computer-readable instructions, which, when executed by one or more processors, enable the one or more processors to execute the steps of the FTP file download method based on the Hongmeng system as described in any one of claims 1 to 6.

9. A computer device, characterized in that: include: one or more processors, and memory; Computer-readable instructions are stored in the memory. 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 6 are performed.