Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the following description, suffixes such as "module", "component", or "unit" used to denote elements are used only for facilitating the explanation of the present invention, and have no specific meaning in itself. Thus, "module", "component" or "unit" may be used mixedly.
Referring to fig. 1, a schematic diagram of a hardware environment for operating a file transfer method according to an embodiment of the present invention is shown. As shown in fig. 1, the file transfer system 100 includes a terminal device 10, a file transfer device 20, and an FTP server 30. The terminal device 10 and the file transfer device 20, and the file transfer device 20 and the FTP server 30 are connected by communication via a network 40. Specifically, in this embodiment, a serial communication connection is established between the terminal device 10 and the file transmission device 20 in a short-distance wired or wireless communication manner, that is, the terminal device 10 is provided with a serial interface 11 and aserial communication circuit 12, and the file transmission device 20 is provided with a serial interface 21 and a serial communication circuit 22, respectively. In other embodiments, the serial interface and the serial communication circuit may be collectively referred to as a serial communication unit or a serial communication module. The file transfer device 20 and the FTP server 30 can be connected in wired or wireless FTP communication via a local area network or a wide area network.
The terminal device 10 may be implemented in various terminals having data operation capability, and may include, for example, terminal devices such as a mobile phone, a tablet computer, a notebook computer, a palm top computer, a Personal Digital Assistant (PDA), a Portable Media Player (PMP), a navigation device, a wearable device, a smart band, a pedometer, and fixed terminals such as a Digital TV, a desktop computer, and the like. Preferably, the file transfer device 20 may be, but is not limited to, a data relay device in a communication system such as a router, a set-top box or a digital switch.
The FTP server 30 is a control center of the file transfer system 100. Specifically, in the embodiment of the present invention, the FTP server 30 manages the terminal devices 10 in the file transfer system 100 and stores file information required by the terminal devices 10. It is understood that other information, such as the identity authentication information of the file transfer device 20 and the terminal device 10, may also be stored on the FTP server 30.
With continued reference to fig. 1, the document transmission device 20 is further provided therein with a memory 23, a display unit 24, an input unit 25, a processor 26, and the like. Those skilled in the art will appreciate that the configuration of the document delivery device 20 shown in FIG. 1 does not constitute a limitation of the document delivery device 20, and that the document delivery device 20 may include more or fewer components than shown, or some components may be combined, or a different arrangement of components. Similarly, the structure of the terminal device 10 shown in fig. 1 does not constitute a limitation of the terminal device 10, and the terminal device 20 may include more or less components than those shown, or combine some components, or arrange different components.
The memory 23 may be used to store software programs as well as various data. The memory 23 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as user data, etc.) created according to the use of the file transfer device 20, and the like. Further, the memory 23 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
In this embodiment, the memory 23 is an internal memory, and after the file transfer device 20 establishes a TCP link connection with the FTP server 30, a protocol stack buffer and a user data buffer may be dynamically allocated for a data link. In another embodiment, the internal memory further dynamically allocates a file system cache for the data link. In the present embodiment, a file transfer program is stored in the program storage area of the memory 23.
The display unit 24 is used to display information input by the user or information provided to the user. The Display unit 24 may include a Display panel, which may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like. In the present embodiment, the display unit 24 may use an LED indicator light or the like to give the user an indication of whether the communication connection is established. For example, when the LED indicator lights up or displays green, it indicates that the serial communication connection between the mobile terminal 10 and the file transfer device 20 or the FTP link connection between the file transfer device 20 and the FTP server 30 has been established.
The input unit 25 may be used to receive numeric or character information input by a user through an input device such as a keyboard, and to generate key signal inputs related to user settings and function control of the file transfer device 20. Specifically, the input unit 25 may include a touch panel and other input devices. The touch panel, also called a touch screen, may collect touch operations of a user (for example, operations of the user on or near the touch panel using any suitable object or accessory such as a finger, a stylus, etc.) and drive the corresponding connection device according to a preset program. The touch panel may include two parts of a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts it to touch point coordinates, and sends the touch point coordinates to the processor 26, and can receive and execute commands from the processor 26. In addition, the touch panel may be implemented in various types such as a resistive type, a capacitive type, an infrared ray, and a surface acoustic wave. The input unit 25 may include other input devices in addition to the touch panel. In particular, the other input devices may include, but are not limited to, one or more of a physical keyboard, a function key (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like, which are not limited herein.
Further, the touch panel may cover the display panel, and when the touch panel detects a touch operation thereon or nearby, the touch panel transmits the touch operation to the processor 26 to determine the type of the touch event, and then the processor 26 provides a corresponding visual output on the display panel according to the type of the touch event. Although the touch panel and the display panel are two independent components to implement the input and output functions of the file transfer device 20 in the present embodiment, in some embodiments, the touch panel and the display panel may be integrated to implement the input and output functions of the file transfer device 20, and this is not limited herein.
The processor 26 is a control center of the terminal device, connects various parts of the entire terminal device by various interfaces and lines, performs various functions of the terminal device and processes data by running or executing software programs and/or modules stored in the memory 23 and calling data stored in the memory 23, thereby performing overall monitoring of the terminal device. Processor 26 may include one or more processing units; preferably, the processor 26 may integrate an application processor, which primarily handles operating systems, user interfaces, applications, etc., and a modem processor, which primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 26.
The various embodiments described herein may be implemented using a computer-readable medium using, for example, computer software, hardware, or any combination thereof. For a hardware implementation, the embodiments described herein may be implemented using at least one of Application Specific Integrated Circuits (ASICs), digital Signal Processors (DSPs), digital Signal Processing Devices (DSPDs), programmable Logic Devices (PLDs), field Programmable Gate Arrays (FPGAs), processors, controllers, micro-controllers, microprocessors, electronic units designed to perform the functions described herein, and in some cases, such embodiments may be implemented in the processor 26. For a software implementation, the implementation such as a process or a function may be implemented with a separate software module that allows performing at least one function or operation. The software code may be embodied by a software application (or program) written in any suitable programming language, which may be stored in memory 23 and executed by processor 26.
The server 30 is provided with a storage device 31, and the storage device 31 stores necessary programs and data required for the operation of the server 30. In an embodiment of the present invention, the storage device 31 stores at least file information required by the terminal device 10.
The implementation and steps of the document transmission method provided in the present application will be further explained with reference to fig. 2 and with reference to the devices in the document transmission system 100.
Referring to fig. 2, a flowchart illustrating steps of a file transmission method according to an embodiment of the invention is shown. The file transmission method is applied to a file transmission device 20. In this embodiment, the execution order of the steps in the flowchart shown in fig. 2 may be changed and some steps may be omitted according to different requirements. As shown in fig. 2, the file transmission method mainly includes the following steps:
step 201: and responding to a control instruction sent by the terminal equipment, and establishing control link connection with the FTP server.
Specifically, when the terminal device 10 needs to obtain a file from the FTP server 30, the terminal device 10 sends a predetermined first AT command to the file transfer device 20 to be in communication with the predetermined FTP server. The first AT instruction is an AT + FTPLOGIN instruction and is used for designating an FTP server and a communication port; that is, the first AT command carries or includes the designated FTP server information and the communication port information of the FTP server. The file includes, but is not limited to, a file formed from images, text information, video information, or voice information, and one or more combinations thereof.
The file transfer device 20, upon receiving the first AT instruction sent from the terminal device 10, establishes a TCP control link connection with the FTP server in response to the first AT instruction. Specifically, the file transfer device 20 transmits login information of the file transfer device 20 to the FTP server according to the FTP protocol to complete the login of the device on the FTP server 30. The login information includes, but is not limited to, user information and authentication information of the file transfer device 20, such as an authentication code. When the file transfer device 20 completes the FTP login in the FTP server 30, i.e., the TCP control link connection is established between the file transfer device 20 and the FTP server 30. After the TCP control connection is established, command transmission is possible among the terminal device 10, the file transfer device 20, and the FTP server 30.
Step 202: responding to a download file designation instruction sent by the terminal equipment, and establishing data link connection with the FTP server.
After the TCP control link connection is established, the file transfer server 20 may receive a file download designation instruction transmitted from the terminal device 10. Specifically, the terminal device 10 sends a preset second AT instruction to specify a file to be downloaded, where the second AT instruction is AT + FTPGET, and includes file information to be downloaded, such as a file name and a file address.
After receiving the second AT command, the file transfer server 20 sends a PASV command to establish a data link connection with the FPT server 30. The PASV command operates passively for the TCP protocol. In this manner, the file transfer server 20 sends a connection request to the FTP server port, and the FTP server receives the connection request and establishes a data link to transfer data.
Step 203: and sending a file downloading instruction to the FTP server to control the data link connection to start the file downloading operation.
In this embodiment, after the data link connection is established, the file transfer device 20 sends a file download instruction to the FTP server 30, that is, the file transfer device 20 sends a RETR command to the FTP server 30 to request the FTP server 30 to copy the file in the specified path to the file transfer device 20, and at this time, the data link connection channel starts to perform a file download operation.
Step 204: and in the process of downloading the file, controlling to send a control link connection keep-alive instruction to the FTP server at a preset time interval.
In the present embodiment, during the file downloading process, the file transfer device 20 sends the control link connection keep-alive instruction to the FTP server 30 at a preset time interval, so that the control link can be prevented from being kicked off by the FTP server 30 due to too long idle time during the file downloading process. Wherein, the control link connection keep-alive instruction is a NOOP instruction in the FTP protocol.
In the file transfer method provided by the present application, during the file transfer process between the file transfer device 20 and the FTP server 30, the file transfer device 20 sends the NOOP instruction at a preset time interval, for example, 30S, until the file download process is finished. Therefore, the link keep-alive function can be achieved, and the control link is prevented from being removed by the FTP server 30 due to overlong idle time in the file downloading process.
In another embodiment, the file transfer method further includes:
after receiving the file data from the FTP server 30, the file transfer device 20 temporarily stores the received file data in a user data cache region, wherein the capacity of the user data cache region is greater than the capacity of a protocol stack cache; and sending the file data temporarily stored in the user data cache region to the terminal equipment through serial port communication. In a specific embodiment, the user data buffer is a circular queue with a preset capacity according to the system resource capacity.
In this embodiment, a user data cache area capable of caching more data is additionally added, so that the file data is stored in the cache as soon as possible, and therefore, it is possible to avoid a download interruption that would otherwise be caused by the fact that the file download may be completed because the connection between the file transfer device 20 and the FTP server 30 is released without the serial port between the file transfer device 20 and the terminal device 10 having sent out the data in the cache.
In addition, the file transfer method further comprises: when detecting that the data link or the control link is unexpectedly disconnected, the control unit preferentially transmits the data in the user data buffer area to the terminal device 10, and then prompts the disconnection of the link.
In another specific embodiment, the internal memory of the file transfer device 20 further includes a local file system storage area. The file transmission method further comprises the following steps: after receiving the file data from the FTP server 30, the file data temporarily stored in the user data cache area is stored in the local file system storage area of the file transfer device 20.
In this way, the file that the terminal device 10 needs to download is already stored in the local file system of the file transfer device 20, i.e., the terminal device 10 acquires data of any offset and length by instructing the AT + FSRF instruction.
Specifically, when the file transfer device 20 stores a file downloaded from an FTP server in a local file system, the file transfer device 20 reads file data of an arbitrary offset and length from the local file system storage area in response to a file reading instruction sent from the terminal device 10; and transmitting the read file data to the terminal device 10.
As such, in this embodiment, by storing the downloaded file in the local file system of the file transfer device 20, two operations of downloading and reading the file by the terminal device 10 can be realized, so that the way in which the terminal device 10 acquires the file is more flexible and convenient.
Referring to fig. 3, a flowchart of a file transfer method according to another embodiment of the invention is shown. Compared with the embodiment shown in fig. 2, the file transmission method provided in this embodiment further includes, afterstep 204, step 205:
and responding to an instruction for closing the file transmission service sent by the terminal equipment, and controlling to close the control link connection, wherein the terminal equipment sends the instruction for closing the file transmission service to the file transmission equipment when the file downloading is completed.
Specifically, when the downloading of the file to be downloaded by the terminal device 10 is completed, the terminal device 10 sends an instruction to close the file transfer service to the file transfer device 20. Thereafter, the file transfer device 20 controls to close the TCP control link connection established with the FTP server 30, that is, the control link connection between the file transfer device 20 and the FTP server 30 is disconnected, in response to the received instruction. When the control link is disconnected, the data link between the file transfer device and the FTP server 30 is also automatically disconnected.
Furthermore, it will be understood by those skilled in the art that all or part of the steps of the method according to the above embodiments may be implemented by hardware associated with at least one program instruction, where the at least one program may be stored in a computer-readable storage medium, and when executed, the at least one program may implement the steps of the file transfer method according to any one of the embodiments of the present invention.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be substantially or partially embodied in the form of a software product, where the computer software product is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk), and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the file transmission method according to the embodiments of the present invention.
The foregoing is illustrative of embodiments of the present invention, and it should be noted that modifications and embellishments may be made by those skilled in the art without departing from the principle of the embodiments of the present invention, and these modifications and embellishments are also considered to be within the scope of the present invention.