Implementation of FTP protocol using Indy Tidftp control

Source: Internet
Author: User
Tags ftp integer ftp protocol

Now a lot of applications need to upload and download large files, HTTP way to upload large files have certain limitations. Fortunately, ftp as a very old and very mature protocol can efficiently and stably complete the upload of large files, and can be perfect for the continuation of the transmission. Just take the movie I wrote. Server Management program, after the comparison of various schemes, found that the use of FTP can be perfect to achieve the requirements. But to achieve FTP through the WinSocket library is a hassle, but fortunately there is a indy--package that wraps most of the network protocols.

By Indy, programmers can program in a blocking way, leaving out crappy winsocket asynchronous patterns and using the same blocking programming pattern as UNIX systems. In this way, the programmer can well handle the running process of the program. Below, we enter into the TIDFTP world of Indy.

1. Description of the control

Using the Tidftp control in Indy 9, you can upload and download files via FTP.

2. The specific use of the control

(1) Control property settings

Default properties, properties that are directly related to server connections, such as host names and users, are set when a connection is established. The values for the Recvbuffersize and sendbuffersize two properties need to be set. In addition, you need to specify the TransferType attribute based on the file type you want to transfer, and the other properties are set by default values.

Recvbuffersize description (Default is 8192 bytes): This property is an integer variable that specifies the size of the accept buffer used for the connection.

Sendbuffersize description (Default is 32768 bytes): This property is also an integer variable that specifies the maximum value of the send buffer used by the connection. When the property is in the Writestream method, it can be used to tstream specify the number of blocks to send the content. If the content to be sent is greater than the value of this property, the sending content is divided into multiple blocks to send.

TransferType description (Default is Ftbinary): This property is a tidftptransfertype type variable. Used to specify whether the transport content is binary (ftbinary) or ASCII (FTASCII). Applications need to transfer executables, compress files, and multimedia files in binary mode, and use ASCII to transmit text-type data, such as text or hypertext.

(2) Event response for the control

Ondisconnected Response: Tnotifyevent class for responding to a disconnected (disconnect) event. The response is triggered when the Disconnect method is invoked to close the socket. The application must specify the procedure for the event response to be appropriate for the Disconnect event.

Onstatus Response: Tidstatusevent class. The response is triggered when the state of the current connection changes. This event can be triggered by the Dostatus method and supplied to the event controller properties. Axstatus is the Tidstatus value of the current connection; Aaargs is an optional parameter for formatting functions that will be used to construct text messages that represent the state of the current connection.

Onwork response: Onword is the response controller for Tworkevent class events. Onwork is used to associate DoWork methods to notify Indy components and classes when a buffer read-write operation is invoked. It is generally used to control the updates of progress bars and window elements. Aworkmode represents the mode of the current operation where the wmread-component is reading the data, and the wmwrite-component is sending the data. Aworkcount indicates the byte count of the current operation.

Onworkbegin Response: Tworkbeginevent class. When a buffer read-write operation initializes, the event association Beginwork method is used to notify Indy components and classes. It is generally used to control the updates of progress bars and window elements. Aworkmode represents the mode of the current operation where the wmread-component is reading the data, and the wmwrite-component is sending the data. Aworkcountmax is used to indicate the maximum number of bytes for an operation sent to the Onworkbegin event, and a value of 0 represents the unknown.

Onworkend Response: Tworkendevent class. When a buffer read-write operation terminates, the event association Endwork method is used to notify Indy components and classes. Aworkmode represents the mode of the current operation where the wmread-component is reading the data, and the wmwrite-component is sending the data. Aworkcount represents the number of bytes in the operation.

In the event response, it is mainly through the above five kinds of event response to control program. In general, set the interface notification in the ondisconnected, set the state of the current operation in the Onstatus, and implement the display of status bars and other parameters in the onwork. , and in Onworkbegin and Onworkend, the interface between the beginning of transmission and the end of transmission is set respectively.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.