File transfer methods, devices, electronic devices, and computer-readable storage media

By calculating the file hash value and attribute information, the server generates transmission information, and the client transmits the file content in chunks according to the data block size. This solves the problem of excessive resource consumption caused by file fragmentation and achieves efficient file transmission.

CN118646748BActive Publication Date: 2025-12-02CCB FINTECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410810664.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2025-12-02
Estimated Expiration
2044-06-21

AI Technical Summary

Technical Problem

Existing technologies cause excessive resource consumption during file transfer due to file fragmentation, resulting in insufficient file descriptors, which affects the correct operation of the computer and leads to excessive consumption of storage resources, especially when transferring large files.

Method used

By calculating the file's hash value and attribute information, the server generates file transfer information. The client then transfers the file content in blocks according to a preset data block size and writes it directly to the target file based on the block number, thus avoiding the use of multiple file descriptors.

Benefits of technology

It effectively avoids the problem of insufficient file descriptors, improves file transfer efficiency, reduces system resource consumption, and ensures the integrity and speed of transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118646748B_ABST
    Figure CN118646748B_ABST
Patent Text Reader

Abstract

This application provides a file transfer method, apparatus, electronic device, and computer-readable storage medium, relating to the field of data transmission technology. The method includes: acquiring file attribute information of a file to be transferred, calculating the hash value of the file to be transferred, and sending the file attribute information and the hash value of the file to be transferred to a server; receiving file transfer information from the server; if the file to be transferred is determined to be a new file based on the file transfer information, reading the file content of the file to be transferred according to a preset data block size, determining the number of the current data block, and sending the current data block and its number to the server, until all data blocks corresponding to the file content of the file to be transferred and their corresponding numbers are sent to the server, so that the server can write all received data blocks into a target file according to their respective numbers. This application effectively avoids the problem of excessive resource consumption during file transfer leading to transmission failure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data transmission technology, and in particular to a file transfer method, a file transfer device, an electronic device, and a computer-readable storage medium. Background Technology

[0002] Currently, when multiple users are in different physical locations during file transfer and need to consolidate electronic files into one location, or when it is necessary to retrieve electronic files located in different physical locations, the existing method for uploading large files is usually to divide the file into different file fragments, the server receives and stores the file fragments, and then reassembles the file fragments into the target file.

[0003] However, existing technologies have the following problems: each file fragment requires a file descriptor, but file descriptors are valuable resources in a computer. Therefore, a large number of file fragments can lead to a shortage of file descriptors, which will affect the correct operation of the computer, the operation of other applications on the computer, or cause the transmission to fail due to the inability to obtain resources correctly; when merging file fragments, the fragment itself and the target file require two storage resources, especially when transmitting large files, the storage resources required will be even greater; in addition, operations on two different storage resources are required, which will also consume more resources. Summary of the Invention

[0004] This application provides a file transfer method, apparatus, electronic device, and computer-readable storage medium to solve the problem of excessive resource consumption caused by file fragmentation during file transfer in the prior art.

[0005] A first aspect of this application provides a file transfer method, comprising:

[0006] In response to a file transfer command, the system obtains the file attribute information of the file to be transferred, calculates the hash value of the file to be transferred based on its content, and sends the file attribute information and the hash value of the file to be transferred to the server.

[0007] Receive file transfer information from the server, the file transfer information being generated by the server after matching existing files on the server based on the file attribute information and the hash value;

[0008] If the file to be transferred is determined to be a new file based on the file transfer information, the file content of the file to be transferred is read sequentially according to the preset data block size. The number of the current data block is determined based on the start and end positions of the current data block in the file content of the file to be transferred. The current data block and its number are sent to the server. This process continues until all data blocks corresponding to the file content of the file to be transferred and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file generated after determining that the file to be transferred is a new file according to the numbers of each data block.

[0009] Optionally, the method further includes:

[0010] If the file to be transferred is determined to be a resumed file based on the file transfer information, the number of the transferred data block is obtained from the server, the start and end positions of the transferred data block in the file content of the file to be transferred are determined based on the number of the transferred data block, and the current reading position is determined based on the start and end positions of the transferred data block in the file content of the file to be transferred.

[0011] The file content of the file to be transmitted is read sequentially from the current reading position according to the preset data block size. The number of the current data block is determined based on the start and end positions of the current data block in the file content of the file to be transmitted. The current data block and the number of the current data block are sent to the server. This process is repeated until all data blocks corresponding to the file content of the file to be transmitted are sent to the server, so that the server can write all the received data blocks into the target file according to the numbers of each data block.

[0012] Optionally, the file transfer information includes the file name of the file to be transferred. The file transfer information is generated by the server after matching existing files on the server based on the file attribute information and the hash value, and includes:

[0013] If the server already has a file whose file name matches the file name of the file to be transmitted, and the hash value calculated based on the file content of that file is the same as the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a retransmission file.

[0014] If the server already has a file whose file name matches the file name of the file to be transmitted, but the hash value calculated based on the file content of that file is different from the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a resumed file.

[0015] If the server does not have a file whose file name matches the file name of the file to be transmitted, and the server does not have a file whose hash value calculated based on the file content is the same as the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a new file.

[0016] Optionally, if the file to be transmitted is determined to be a retransmission file based on the file transfer information, the method further includes:

[0017] Receive retransmission confirmation information from the server;

[0018] If it is confirmed that a retransmission operation will be performed on the file to be transmitted, the file content of the file to be transmitted will be read sequentially according to a predetermined numbering order, and the current data block and its number will be sent to the server until all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file according to their numbers, and replace the existing corresponding data blocks in the target file with the received data blocks.

[0019] Optionally, after sending all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers to the server, the method further includes:

[0020] Receive file transfer completion information from the server;

[0021] The file transfer completion information is generated by the server when the hash value calculated based on the file content of the target file matches the hash value of the file to be transferred.

[0022] Optionally, sending the current data block and its number to the server includes:

[0023] Generate a random string as the original checksum of the current data block, and append the original checksum to the end of the current data block;

[0024] The current data block, including the original checksum, is encrypted using a preset symmetric encryption algorithm. The encrypted data block, the number of the current data block, and the original checksum are then uploaded to the server.

[0025] After sending the current data block and its number to the server, the method further includes:

[0026] Receive data block transmission status information from the server for the current data block;

[0027] The data block transmission status information is generated by the server after decrypting the encrypted data block using the preset symmetric encryption algorithm, based on the matching result between the decrypted checksum and the original checksum.

[0028] Optionally, the verification code is generated based on the matching result between the decrypted verification code and the original verification code, including:

[0029] If the decrypted verification code does not match the original verification code, the server generates data block transmission status information indicating that the current data block transmission has failed.

[0030] If the decrypted verification code matches the original verification code, the server writes the current data block into the target file according to the current data block number, and generates data block transmission status information indicating that the current data block transmission is complete after completing the writing operation of the current data block.

[0031] Optionally, sending the current data block and its number to the server further includes:

[0032] If no data block transmission status information indicating the completion of the current data block transmission is received from the server within the first time period, the encrypted data block will be re-uploaded to the server through the current transmission channel;

[0033] If no data block transmission status information indicating that the re-uploaded data block transmission is complete is received from the server within the second time period, it is determined whether there is a data block retransmission queue.

[0034] If a data block retransmission queue already exists, the current data block is placed into the data block retransmission queue, and each data block in the data block retransmission queue is re-uploaded to the server through the data block retransmission queue.

[0035] If a data block retransmission queue does not exist, a data block retransmission queue is created, the current data block is placed into the data block retransmission queue, and each data block in the data block retransmission queue is re-uploaded to the server through the data block retransmission queue.

[0036] Optionally, the method further includes:

[0037] Create a temporary file for any data block in the data block retransmission queue:

[0038] If, after performing a preset number of retransmission operations, the current data block still does not receive data block transmission status information from the server indicating that the current data block transmission is complete, the number of the current data block is written into the temporary file;

[0039] After the other data blocks of the file to be transmitted are transmitted, the number in the temporary file is read, and the corresponding data block is retransmitted according to the read number. If the data block transmission status information indicating that the current data block transmission is completed is received from the server within the first time period, the number of the current data block is deleted from the temporary file; otherwise, an alarm message indicating that the current data block transmission has failed is generated.

[0040] A second aspect of this application provides a file transfer device, comprising:

[0041] The transmission request module is configured to, in response to a file transmission command, obtain file attribute information of the file to be transmitted, calculate the hash value of the file to be transmitted based on the file content of the file to be transmitted, and send the file attribute information and the hash value of the file to be transmitted to the server.

[0042] The file transfer information receiving module is configured to receive file transfer information from the server. The file transfer information is generated by the server after matching existing files on the server based on the file attribute information and the hash value.

[0043] The file transfer module is configured to, if determined based on the file transfer information that the file to be transferred is a new file, sequentially read the file content of the file to be transferred according to a preset data block size, determine the number of the current data block based on the start and end positions of the current data block in the file content of the file to be transferred, and send the current data block and its number to the server, until all data blocks corresponding to the file content of the file to be transferred and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file generated after determining that the file to be transferred is a new file according to the number of each data block.

[0044] A third aspect of this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;

[0045] The memory stores computer-executed instructions;

[0046] The processor executes computer execution instructions stored in the memory to implement the method described above.

[0047] A fourth aspect of this application provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, are used to implement the method described above.

[0048] A fifth aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0049] This application reads file content in chunks directly during file transmission, so that when the server receives the file, it only needs to generate a target file. The content of each file is directly written to the corresponding position of the target file according to the data block number. This avoids the problem of insufficient file descriptors that may occur when transmitting a large number of files at the same time, which may lead to transmission failure. Attached Figure Description

[0050] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0051] Figure 1 A flowchart illustrating the file transfer method provided in this application embodiment;

[0052] Figure 2 This is a schematic diagram of the data block transmission process provided in an embodiment of this application;

[0053] Figure 3 A flowchart of the data block retransmission process provided in this application embodiment;

[0054] Figure 4 A schematic block diagram of a file transfer device provided in an embodiment of this application;

[0055] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0056] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0057] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for illustration and explanation of the embodiments of this application and are not intended to limit the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0058] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positional relationship and movement of the components in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.

[0059] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application. It is understood that in the technical solutions of this application, the acquisition, collection, storage, use, processing, transmission, provision, disclosure, and application of data all comply with the provisions of relevant laws and regulations. It should be noted that in the embodiments of this application, certain software, components, models, and other existing industry solutions may be mentioned. These should be considered exemplary, and their purpose is merely to illustrate the feasibility of implementing the technical solutions of this application, but does not mean that the applicant has already used or necessarily used such solutions.

[0060] like Figure 1 As shown, in a first aspect, this application provides a file transfer method applied to a client, the method comprising:

[0061] S100: In response to a file transfer command, obtain the file attribute information of the file to be transferred, calculate the hash value of the file to be transferred based on the file content of the file to be transferred, and send the file attribute information and the hash value of the file to be transferred to the server.

[0062] S200: Receive file transfer information from the server. The file transfer information is generated by the server after matching existing files on the server based on file attribute information and hash value.

[0063] S300. If the file to be transmitted is determined to be a new file based on the file transfer information, the file content of the file to be transmitted is read sequentially according to the preset data block size. The number of the current data block is determined based on the start and end positions of the current data block in the file content of the file to be transmitted. The current data block and its number are sent to the server. This process continues until all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file generated after determining that the file to be transmitted is a new file according to the numbers of each data block.

[0064] Thus, by directly reading file content in chunks during file transmission, the server only needs to generate one target file when receiving the file. The content of each file is directly written to the corresponding position of the target file according to the data block number, thereby avoiding the need to occupy a large number of file descriptors and effectively avoiding the problem of insufficient file descriptors that may lead to transmission failure when transmitting a large number of files at the same time.

[0065] In step S100, after receiving the file transfer instruction, the client first checks the file to be transferred, including but not limited to checking whether the file format meets the requirements and whether the file content is complete. If the check fails, a prompt message is generated to inform the user of the corresponding problem, and subsequent operations are stopped. In this way, by checking the content to be transferred before formal transmission, this application effectively ensures that the transmitted content meets the requirements and reduces retransmissions caused by non-compliant content. It is understood that the file check can be customized as needed. File format and integrity checks can be implemented using existing methods, and are not limited here. After the file check of the file to be transferred passes, the size of the file to be transferred is obtained, the file content is read, and the hash value of the file to be transferred is calculated based on the file content. For example, the MD5 value of the file to be transferred is calculated, where MD5 refers to the fifth version of the Message Digest algorithm. After obtaining the MD5 value of the file to be transferred, the MD5 value and file attributes, such as the file name of the file to be transferred, are sent to the server to notify the server that the file is to be transferred.

[0066] In step S200, the server performs file matching locally based on the received filename and MD5 hash, and generates corresponding file transfer information based on the matching results. Specifically, the file transfer information is generated by the server matching existing files on the server based on file attribute information and hash values, including:

[0067] S210. If the server already has a file with a name matching the filename of the file to be transmitted, and the hash value calculated based on the file content of that file is the same as the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a retransmission file. The server queries local files. If a file with the same name exists, it further reads the file content of that file, calculates the MD5 value of the file content, and matches the obtained MD5 value with the MD5 value of the received file to be transmitted. If they match, it is determined that the server already has the same file. The server then sends file transmission information to the client indicating that the file to be transmitted is a retransmission file and whether to retransmit the file to be transmitted.

[0068] S220. If the server already has a file with a name matching the file to be transferred, but the hash value calculated based on the file content of that file is different from the hash value of the file to be transferred, the server generates file transfer information indicating that the file to be transferred is a resumed file. If the server finds a local file with the same name as the file to be transferred, but the MD5 value calculated based on the file content is different from the MD5 value of the file to be transferred, it indicates that the file content of the file to be transferred has not been completely transferred. The server determines that the current file to be transferred is a resumed file and sends file transfer information indicating that the file to be transferred is a resumed file to the client.

[0069] S230. If the server does not have a file whose filename matches the filename of the file to be transmitted, and the server does not have a file whose hash value calculated based on the file content is the same as the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a new file. If the server does not find a local file with the same filename as the file to be transmitted, and whose MD5 value calculated based on the file content is the same as the MD5 value of the file to be transmitted, then the server determines that the current file to be transmitted is a new file, sends the file transmission information indicating that the file to be transmitted is a new file to the client, and creates a new target file locally to receive the data blocks of the file to be transmitted.

[0070] In step S300, if the client receives file transfer information from the server indicating that the file to be transferred is a new file, the client divides the file content of the file to be transferred into blocks of a fixed size and numbers each data block according to its start and end positions in the file. For example, the file content data of the file to be transferred can be divided into blocks of a fixed size of Mkb, and the start and / or end positions of each data block can be obtained. The blocks are then numbered based on their start and / or end positions. For example, if the start position of a data block is the m-th byte of the file content, then the data block is numbered m. Alternatively, the data blocks can be numbered sequentially as 1, 2, 3, ..., n according to their position in the file content. Since the size of each data block is fixed, the position of each data block in the file content can be determined based on its number. The numbering method for the data blocks is not limited here. Understandably, if the size of the last data block is less than Mkb, it can be padded with special characters until it reaches Mkb. Alternatively, if the size of the last data block is less than Mkb, it can be read directly according to its actual size. This is not a limitation here. During file transfer, the client reads the file content sequentially. For example, if the file content is divided into N data blocks, the client reads the file content sequentially according to the data block numbers 1 to N. For instance, it first reads data block number 1, sends this data block and its number to the server, then reads data block number 2, and so on, until all N data blocks have been sent. After receiving the data blocks sent by the client, the server calculates the position of each data block in the target file based on its number. The server then writes each data block directly into the corresponding position in the target file. Simultaneously, the server creates a temporary file; each time the server writes a data block to the target file, it writes the block number into this temporary file. In this way, by directly dividing the file content of the file to be transferred into data blocks and writing them directly to the target file, multiple files do not need to be created during file transfer, and system file descriptor resources are not occupied, thus improving file transfer efficiency and reducing system resource consumption.

[0071] In step S300, the method of this application further includes: if it is determined that the file to be transmitted is a resumed file based on the file transmission information, obtaining the number of the transmitted data block from the server, determining the start and end positions of the transmitted data block in the file content of the file to be transmitted based on the number of the transmitted data block, determining the current reading position based on the start and end positions of the transmitted data block in the file content of the file to be transmitted; reading the transmission file content of the file to be transmitted sequentially from the current reading position with a preset data block size, determining the number of the current data block based on the start and end positions of the current data block in the file content of the file to be transmitted, sending the current data block and the number of the current data block to the server, until all data blocks corresponding to the file content of the file to be transmitted are sent to the server, so that the server can write all the received data blocks into the target file according to the number of each data block. If the file to be transferred is a resumed file, the server sends the file transfer information to the client along with the numbers of the data blocks that have already been transferred. This allows the client to identify the untransferred data blocks based on the completed transfers and determine the current reading position based on the start and end positions of the transferred blocks. For example, if the file is divided into 10 blocks and blocks 1-5 have been transferred, the client will start reading from block 6. Alternatively, the client can record the numbers of failed transfers during the transfer process. In the next resume transfer, the client only needs to transfer the data block corresponding to the recorded number.

[0072] In step S300, if the file to be transmitted is determined to be a retransmission file based on the file transfer information, the method further includes: receiving retransmission confirmation information from the server. When the server determines that the current file to be transmitted is a retransmission file, it sends a confirmation message to the client indicating whether to retransmit. If the retransmission operation is confirmed, the file content of the file to be transmitted is read sequentially according to a predetermined numbering order. The current data block and its number are sent to the server until all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers are sent to the server. This allows the server to write all received data blocks into the target file according to their numbers and replace existing corresponding data blocks in the target file with the received data blocks. When the client confirms the retransmission of the file to be transmitted, it sends the data blocks of the file to be transmitted to the server according to the steps for retransmitting a new file. The server then replaces the corresponding transmitted data blocks in the target file with the received data blocks according to their numbers.

[0073] In this application, after the client sends all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers to the server, the method further includes: receiving file transmission completion information from the server, wherein the file transmission completion information is generated by the server when the hash value calculated based on the file content of the target file matches the hash value of the file to be transmitted. For example, after the client sends all data blocks of the file to be transmitted to the server, the server calculates the MD5 value of the file content of the target file. If the calculated MD5 value is the same as the original MD5 value of the file to be transmitted, the server confirms that the data block transmission of the file to be transmitted is complete and returns file transmission completion information to the client.

[0074] like Figure 2 As shown in this application, when the client performs new transmission, retransmission, or resume transmission of the file to be transmitted, the method of sending the current data block and the number of the current data block to the server further includes: generating a random string as the original checksum of the current data block, appending the original checksum to the end of the current data block; encrypting the current data block including the original checksum using a preset symmetric encryption algorithm such as the DES algorithm, i.e., the data encryption standard algorithm, and uploading the encrypted data block, the number of the current data block, and the original checksum to the server.

[0075] After sending the current data block and its number to the server, the method of this application further includes: receiving data block transmission status information from the server for the current data block, wherein the data block transmission status information is generated by the server after decrypting the encrypted data block using a preset symmetric encryption algorithm, and based on the matching result of the decrypted checksum and the original checksum. Upon receiving each encrypted data block, the server decrypts the received data block using the same encryption algorithm, such as the DES algorithm, and matches the obtained checksum with the original checksum of the data block.

[0076] If the decrypted checksum does not match the original checksum, the server considers the data block abnormal, generates data block transmission status information indicating an error in the current data block transmission, and sends this information to the client. If the decrypted checksum matches the original checksum, the server writes the current data block to the target file according to its number, and after completing the write operation, generates data block transmission status information indicating successful transmission of the current data block, and sends this information to the client.

[0077] like Figure 3 As shown, in this application, if the data block transmission fails during the transmission process, the data block is retransmitted using a preset retransmission mechanism. That is, the application's method of sending the current data block and its number to the server also includes:

[0078] S310. If no data block transmission status information indicating completion of the current data block transmission is received from the server within the first time period, the encrypted data block is re-uploaded to the server through the current transmission channel. For example, after the client sends a data block to the server, it records the sending time of the data block. If no data block transmission completion information is received from the server within the first time period after the data block is sent, the data block is re-transmitted through the current transmission channel.

[0079] S320. If no data block transmission status information indicating completion of the re-uploaded data block transmission is received from the server within the second time period, determine whether a data block retransmission queue exists. After retransmitting the data block, record the retransmission time of the data block. If no data block transmission completion information is received from the server within the second time period after the data block is re-uploaded, the client further determines whether a data block retransmission queue exists.

[0080] If a data block retransmission queue already exists, the client adds the currently failed retransmission data block to the data block retransmission queue. The data blocks in the retransmission queue are then retransmitted to the server. For example, if data block 1 and data block 2 already exist in the retransmission queue, the current data block is added to data block 2 in sequence. The data block retransmission queue then synchronizes with the client and server transmission channels to transmit data blocks sequentially. For instance, the data blocks in the retransmission queue are retransmitted one by one.

[0081] If the client detects that there is no data block retransmission queue, the client creates a new data block retransmission queue, puts the current data block at the head of the data block retransmission queue, and re-uploads each data block in the data block retransmission queue to the server.

[0082] When retransmitting data blocks, the method of this application further includes:

[0083] The client creates a temporary file while creating the data block retransmission queue. For any data block in the data block retransmission queue:

[0084] If, after a preset number of retransmissions, the current data block still does not receive a data block transmission status message from the server indicating that the current data block has been successfully transmitted, the current data block's number is written to a temporary file. For example, a set number of retransmissions can be set for each data block in the retransmission queue. If a data block fails to transmit after the preset number of retransmissions, the client writes the data block's number to the temporary file. After all other data blocks in the file to be transmitted (excluding those recorded in the temporary file) have been transmitted, the client reads the numbers from the temporary file and performs retransmission operations on the corresponding data blocks according to the read numbers. If a data block transmission status message indicating that the current data block has been successfully transmitted is received from the server within the first time period, the current data block's number is deleted from the temporary file; otherwise, an alarm message indicating that the current data block transmission failed is generated.

[0085] like Figure 4 As shown, in a second aspect, this application provides a file transfer apparatus, comprising:

[0086] The transmission request module is configured to respond to a file transmission command by obtaining the file attribute information of the file to be transmitted, calculating the hash value of the file to be transmitted based on the file content of the file to be transmitted, and sending the file attribute information and the hash value of the file to be transmitted to the server.

[0087] The file transfer information receiving module is configured to receive file transfer information from the server. The file transfer information is generated by the server after matching existing files on the server based on file attribute information and hash value.

[0088] The file transfer module is configured to, if determined based on file transfer information that the file to be transferred is a new file, read the file content of the file to be transferred sequentially according to a preset data block size, determine the number of the current data block based on the start and end positions of the current data block in the file content of the file to be transferred, and send the current data block and its number to the server, until all data blocks corresponding to the file content of the file to be transferred and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file generated after determining that the file to be transferred is a new file according to the numbers of each data block.

[0089] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing elements; they can be fully implemented in hardware; or some modules can be implemented by processing elements calling software, while others are implemented in hardware. For example, the data acquisition module can be a separate processing element, or it can be integrated into a chip in the above device. Alternatively, it can be stored as program code in the memory of the above device, and its functions can be called and executed by a processing element. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.

[0090] A third aspect of this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;

[0091] The memory stores the instructions that the computer executes;

[0092] The processor executes computer-executable instructions stored in memory to implement the method described above.

[0093] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 5 As shown, the electronic device may include: transceiver 121, processor 122, and memory 123.

[0094] Processor 122 executes computer execution instructions stored in memory, causing processor 122 to perform the scheme in the above embodiments. Processor 122 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0095] The memory 123 is connected to the processor 122 via the system bus and completes communication between them. The memory 123 is used to store computer program instructions.

[0096] Transceiver 121 can be used to obtain the task to be run and its configuration information.

[0097] The system bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. Transceivers are used to enable communication between database access devices and other computers (e.g., clients, read-write libraries, and read-only libraries). Memory may include random access memory (RAM) and may also include non-volatile memory.

[0098] The electronic device provided in this application embodiment can be the terminal device described in the above embodiments.

[0099] A fourth aspect of this application provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, are used to implement the method described above.

[0100] A fifth aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0101] In summary, this application enables secure and rapid file transfer to the server without requiring a server username and password. The server only needs to create a new file and generate a target file; the actual file content is directly written to this file. This avoids consuming a large number of file descriptors, effectively preventing the problem of insufficient file descriptors and subsequent transfer failures when transferring a large number of files simultaneously. Meanwhile, this application establishes a three-level retransmission mechanism: retransmission via the normal transmission channel, a first retransmission via the retransmission channel, and a second retransmission via the retransmission channel. When using the normal transmission channel for retransmission, it reduces transmission failures caused by network jitter, enabling faster processing of block data and improving retransmission efficiency. The first retransmission, performed via an additional retransmission channel, sorts failed blocks. Since data block retransmission and normal transmission use different channels, it effectively solves transmission failures caused by problems with the normal transmission channel, improving the retransmission success rate. The second retransmission via the retransmission channel occurs after other blocks have been transmitted, thus separating it from the normal and first retransmissions in time, reducing channel congestion and the probability of concurrent transmission, further improving the retransmission success rate. Resumption of transmission effectively supplements retransmission by initiating transmission separately to complete the transmission of the remaining blocks. In this application, the client records the numbers of failed data blocks during data block transmission. During subsequent transmissions, only the failed blocks need to be transmitted to complete the entire file transmission, effectively reducing the overhead of retransmitting the entire file again.

[0102] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0103] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A file transfer method, characterized in that, include: In response to a file transfer command, the system obtains the file attribute information of the file to be transferred, calculates the hash value of the file to be transferred based on the file content of the file to be transferred, and sends the file attribute information and the hash value of the file to be transferred to the server. The file attribute information includes the file name of the file to be transferred. Receive file transfer information from the server, the file transfer information being generated by the server after matching existing files on the server based on the file attribute information and the hash value; If, based on the file transfer information, it is determined that the file name and hash value of the file to be transferred are different from the existing files on the server, the file to be transferred is determined to be a new file. The file content of the file to be transferred is read sequentially according to a preset data block size. The number of the current data block is determined based on the start and end positions of the current data block in the file content of the file to be transferred. The current data block and its number are sent to the server. This process continues until all data blocks corresponding to the file content of the file to be transferred and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file generated after determining that the file to be transferred is a new file according to the numbers of each data block. Sending the current data block and its number to the server includes: Generate a random string as the original checksum of the current data block, and append the original checksum to the end of the current data block; The current data block, including the original checksum, is encrypted using a preset symmetric encryption algorithm. The encrypted data block, the number of the current data block, and the original checksum are then uploaded to the server. After sending the current data block and its number to the server, the method further includes: Receive data block transmission status information from the server for the current data block; The data block transmission status information is generated by the server after decrypting the encrypted data block using the preset symmetric encryption algorithm, based on the matching result between the decrypted checksum and the original checksum.

2. The file transfer method according to claim 1, characterized in that, The method further includes: If the file to be transferred is determined to be a resumed file based on the file transfer information, the number of the transferred data block is obtained from the server, the start and end positions of the transferred data block in the file content of the file to be transferred are determined based on the number of the transferred data block, and the current reading position is determined based on the start and end positions of the transferred data block in the file content of the file to be transferred. The file content of the file to be transmitted is read sequentially from the current reading position according to the preset data block size. The number of the current data block is determined based on the start and end positions of the current data block in the file content of the file to be transmitted. The current data block and the number of the current data block are sent to the server. This process is repeated until all data blocks corresponding to the file content of the file to be transmitted are sent to the server, so that the server can write all the received data blocks into the target file according to the numbers of each data block.

3. The file transfer method according to claim 1, characterized in that, The file transfer information is generated by the server after matching existing files on the server based on the file attribute information and the hash value, including: If the server already has a file whose file name matches the file name of the file to be transmitted, and the hash value calculated based on the file content of that file is the same as the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a retransmission file. If the server already has a file whose file name matches the file name of the file to be transmitted, but the hash value calculated based on the file content of that file is different from the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a resumed file. If the server does not have a file whose file name matches the file name of the file to be transmitted, and the server does not have a file whose hash value calculated based on the file content is the same as the hash value of the file to be transmitted, the server generates file transmission information indicating that the file to be transmitted is a new file.

4. The file transfer method according to claim 3, characterized in that, If the file to be transmitted is determined to be a retransmission file based on the file transfer information, the method further includes: Receive retransmission confirmation information from the server; If it is confirmed that a retransmission operation will be performed on the file to be transmitted, the file content of the file to be transmitted will be read sequentially according to a predetermined numbering order, and the current data block and its number will be sent to the server until all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file according to their numbers, and replace the existing corresponding data blocks in the target file with the received data blocks.

5. The file transfer method according to claim 1, characterized in that, After sending all data blocks corresponding to the file content of the file to be transmitted and their corresponding numbers to the server, the method further includes: Receive file transfer completion information from the server; The file transfer completion information is generated by the server when the hash value calculated based on the file content of the target file matches the hash value of the file to be transferred.

6. The file transfer method according to claim 1, characterized in that, The verification code is generated based on the matching result between the decrypted verification code and the original verification code, including: If the decrypted verification code does not match the original verification code, the server generates data block transmission status information indicating that the current data block transmission has failed. If the decrypted verification code matches the original verification code, the server writes the current data block into the target file according to the current data block number, and generates data block transmission status information indicating that the current data block transmission is complete after completing the writing operation of the current data block.

7. The file transfer method according to claim 6, characterized in that, Sending the current data block and its number to the server also includes: If no data block transmission status information indicating the completion of the current data block transmission is received from the server within the first time period, the encrypted data block will be re-uploaded to the server through the current transmission channel; If no data block transmission status information indicating that the re-uploaded data block transmission is complete is received from the server within the second time period, it is determined whether there is a data block retransmission queue. If a data block retransmission queue already exists, the current data block is placed into the data block retransmission queue, and each data block in the data block retransmission queue is re-uploaded to the server through the data block retransmission queue. If a data block retransmission queue does not exist, a data block retransmission queue is created, the current data block is placed into the data block retransmission queue, and each data block in the data block retransmission queue is re-uploaded to the server through the data block retransmission queue.

8. The file transfer method according to claim 7, characterized in that, The method further includes: Create a temporary file for any data block in the data block retransmission queue: If, after performing a preset number of retransmission operations, the current data block still does not receive data block transmission status information from the server indicating that the current data block transmission is complete, the number of the current data block is written into the temporary file; After the other data blocks of the file to be transmitted are transmitted, the number in the temporary file is read, and the corresponding data block is retransmitted according to the read number. If the data block transmission status information indicating that the current data block transmission is completed is received from the server within the first time period, the number of the current data block is deleted from the temporary file; otherwise, an alarm message indicating that the current data block transmission has failed is generated.

9. A file transfer device, characterized in that, include: The transmission request module is configured to respond to a file transmission command by obtaining file attribute information of the file to be transmitted, calculating the hash value of the file to be transmitted based on the file content of the file to be transmitted, and sending the file attribute information and the hash value of the file to be transmitted to the server. The file attribute information includes the file name of the file to be transmitted. The file transfer information receiving module is configured to receive file transfer information from the server. The file transfer information is generated by the server after matching existing files on the server based on the file attribute information and the hash value. The file transfer module is configured to determine that if the file name and hash value of the file to be transferred are different from existing files on the server based on the file transfer information, the file to be transferred is determined to be a new file. The module then reads the file content of the file to be transferred sequentially according to a preset data block size, determines the number of the current data block based on the start and end positions of the current data block in the file content of the file to be transferred, and sends the current data block and its number to the server. This process continues until all data blocks corresponding to the file content of the file to be transferred and their corresponding numbers are sent to the server, so that the server can write all the received data blocks into the target file generated after determining that the file to be transferred is a new file according to the numbers of each data block. Sending the current data block and its number to the server includes: Generate a random string as the original checksum of the current data block, and append the original checksum to the end of the current data block; The current data block, including the original checksum, is encrypted using a preset symmetric encryption algorithm. The encrypted data block, the number of the current data block, and the original checksum are then uploaded to the server. After sending the current data block and its number to the server, the file transfer module is further configured to: Receive data block transmission status information from the server for the current data block; The data block transmission status information is generated by the server after decrypting the encrypted data block using the preset symmetric encryption algorithm, based on the matching result between the decrypted checksum and the original checksum.

10. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-8.

12. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1-8.

Citation Information

Patent Citations

  • Data block uploading and storing system and method

    CN103873507A

  • File storage method, device and equipment and computer readable storage medium

    CN109582644A