The FileTransferStatus, ReceivingFile and SendingFile events of the FtpClient class can all be used to display progress information during an FTP operation.
The FileTransferStatus event is raised for every packet sent or received during a file transfer, while the ReceivingFile and SendingFile events for each file being sent or received to and from the FTP server.
Other events such as the StateChanged, Disconnected, CommandSent and ReplyReceived events can also be used to display information during an FTP operation.
Demonstration
The following example demonstrates how to use the FileTransferStatus and SendingFile events to display progressing information while uploading files to an FTP server. It will also demonstrates how to use the CommandSent and ReplyReceived events to provide logging information during the process
This example assumes that you are in a Windows application and that the form contains 2 labels, 2 progress bars and a listbox.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
FtpClient ftp = new FtpClient(); |
Things you should consider
-
Do you want to know the state of the FTP client? Check the Connected and Busy properties. You can also check the State property for specific state information. The StateChanged event can also be used to know when the state of the FTP client changes.
-
Do you want to continue a multiple-file transfer (when using the ReceiveMultipleFiles or SendingMultipleFiles methods) when one or more of the files being transferred causes an error? Handle the MultipleFileTransferError event.
-
Do you want to prevent routers from prematurely closing the command channel while a long data transfer is taking place. Set the KeepAliveInterval property.