Sample: 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.
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)
The MyCallback method is called when the transfer is finished.
See also: