This blog post provides a C# example in Visual Studio 2005 that can do FTP uploads and downloads in a background thread, and can monitor the progress in a progress bar as well as abort the operation while in progress.
Here is a screenshot:
The VS2005 project files may be downloaded from here:
Visual Studio project on GitHub
Important: We specifically excluded the ChilkatDotNet2.dll from this download. After opening the project, remove the existing reference to ChilkatDotNet2.dll and re-add it using the ChilkatDotNet2.dll you downloaded from the Chilkat web site.
There are two types of activity monitoring: heartbeat event callbacks, and percentage completion callbacks. Heartbeat callbacks are common to all Chilkat components with events. There is a HeartbeatMs property that controls the frequency of AbortCheck events. The component will fire AbortCheck events during any method call (Connect, ChangeRemoteDir, GetFile, PutFile, Syst, etc.) Any operation can be aborted by setting the Abort flag in the AbortCheckEventArgs argument.
Percentage completion events are fired for operations where it makes sense (i.e. in cases where it is possible to know in advance the amount of work yet to be done). Methods such as Connect and ChangeRemoteDir will not fire percentage-completion events. Methods such as GetFile and PutFile (of course) fire PercentDone events.
This example shows how to monitor and abort tasks that happen both in the foreground thread and a background thread. It uses the .NET BackgroundWorker helper class, which is crucial in being able to update Form elements such as a progress bar.
The example’s source code is extensively documented. If you have any questions about how it works, please send email to email@example.com.