You simply need to use Ftp.Abort method.
This method is thread safe. You can use it from any thread.
Put it in the method that is invoked when user cancels the transfer:
C#:
private Ftp _ftp;
private void BtnDownload_Click(object sender, EventArgs e)
{
Thread thread = new Thread(BackgroundThread);
thread.Start();
}
private void BackgroundThread()
{
try
{
_ftp = new Ftp();
_ftp.Connect("ftp-loc");
_ftp.Login("login", "password");
_ftp.Download(path);
_ftp.Close();
}
finally
{
_ftp.Dispose();
_ftp = null;
}
}
private void BtnStop_Click(System.Object sender, System.EventArgs e)
{
this._ftp?.Abort();
}
VB.NET:
Private _ftp As Ftp
Private Sub BtnDownload_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim thread As Thread = New Thread(AddressOf BackgroundThread)
thread.Start()
End Sub
Private Sub BackgroundThread()
Try
_ftp = New Ftp()
_ftp.Connect("ftp-loc")
_ftp.Login("login", "password")
_ftp.Download(path)
_ftp.Close()
Finally
_ftp.Dispose()
_ftp = Nothing
End Try
End Sub
Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me._ftp?.Abort()
End Sub
Please note that this is just a sample code, error handling is missing.