The SendFile, SendMultipleFiles and SendFileToUniqueName methods of the FtpClient class as well as the BeginSendFile/ EndSendFile, BeingSendMultipleFiles/ EndSendMultipleFiles and BeginSendFileToUniqueName/ EndSendFileToUniqueName methods of the AsyncFtpClient class are used to send one or more files to an FTP server.
The SendFile and BeginSendFile/EndSendFile methods send one file to an FTP server while the SendMultipleFiles and BeginSendMultipleFiles/EndSendMultipleFiles methods send one or more files. The SendFileToUniqueName and BeginSendFileToUniqueName/EndSendFileToUniqueName methods also send one file to an FTP server; however, the filename of the remote file will be generated by the FTP server.
All the methods above will send the files into the FTP server's current working directory. If you want to send the files to another location, you could use the ChangeCurrentFolder or BeginChangeCurrentFolder/ EndChangeCurrentFolder, or ChangeToParentFolder or BeginChangeToParentFolder/ EndChangeToParentFolder methods to change the current working folder. The current working folder can be retrieved via the GetCurrentFolder or BeginGetCurrentFolder/ EndGetCurrentFolder methods.
The following example demonstrates how to send multiple files to an FTP server using the SendMultipleFiles method. An asynchronous (non-blocking) demonstration is also available.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
The following example demonstrates how to asynchronously send multiple files to an FTP server using the BeginSendMultipleFiles/ EndSendMultipleFiles methods and provide logging information during the process using the CommandSent and ReplyReceived events. A synchronous (blocking) demonstration is also available.
To clarify the code, instead of using callbacks, we will wait for completion of the operation before calling the matching "End" method. More information is available in the WinForms application and threading topic.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
Are you using Xceed FTP for .NET in a WinForms application? Use the AsyncFtpClient class rather than the FtpClient class.
Do you want the FTP server to initiate the data connection rather than the FTP client? Set the PassiveTransfer property to false.
Do you want the file(s) to be sent in ASCII mode rather than binary? Set the RepresentationType property to ASCII.
Do you want to decrease or increase the period of time after which an FTP operation should timeout? Change the value of the Timeout property.
Do you want to create a log file of the FTP process? Set the TraceWriter property.
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 know when a file is being sent? Handle the SendingFile event.
Do you want to display progress information? Handle the FileTransferStatus event.
Do you want to continue a multiple-file transfer (when using the SendMultipleFiles method) when one or more of the files being transferred causes an error? Handle the MultipleFileTransferError event.
Do you want to abort the FTP operation? Call the Abort method.
Do you want to prevent routers from prematurely closing the command channel while a long data transfer is taking place. Set the KeepAliveInterval property.