GetPutAsync - asynchronous FTP download/upload
A utility for uploading and downloading files asynchronously using FTP.
GetPutAsync sample (both C# and VB.NET) is identical to GetPut sample, but transfers the files asynchronously in the background.
All methods of the Ftp class have the asynchronous versions that behave according to .NET asynchronous methods design patterns.
Sample codes for .NET 2.0
C#
// begin asynchronous transfer IAsyncResult asyncResult = ftp.BeginGetFile( remotePath, localPath, new AsyncCallback(MyCallback), null ); while (!asyncResult.IsCompleted) { // do something else here ... } // finish asynchronous operation and get the result long bytes = ftp.EndGetFile(asyncResult);
VB.NET
' begin asynchronous transfer Dim asyncResult As IAsyncResult asyncResult = ftp.BeginGetFile( _ remotePath, _ localPath, _ New AsyncCallback(AddressOf MyCallback), _ Nothing _ ) Do ' do something else here... Loop While Not asyncResult.IsCompleted ' get the result Dim bytes As Long bytes = ftp.EndGetFile(asyncResult)
Sample codes for .NET 4.0
C#
// begin asynchronous transfer Task<long> asyncTransfer = ftp.GetFileAsync(remotePath, localPath); while (!asyncTransfer.IsCompleted) { // do something else here ... } // get the result long bytes = asyncTransfer.Result;
VB.NET
' begin asynchronous transfer Dim asyncTransfer As Task(Of Long) = ftp.GetFileAsync(remotePath, localPath) Do ' do something else here... Loop While Not asyncTransfer.IsCompleted ' get the result Dim bytes As Long = asyncTransfer.Result