Cancel a SFTP upload or download

Jan 18, 2013 at 2:04 PM

Hi, is there any way to cancel an ongoing sftp upload or download ?

I should cancel from the callback method of DownloadFile and UploadFile.

Thanks

Coordinator
Jan 19, 2013 at 11:52 PM
Edited Jan 19, 2013 at 11:53 PM

Hey

 

Please check out latest code,

I just added two properties to allow you to cancel either upload or download opration.

Here is a usage example:

 

using (var sftpClient = new SftpClient(connectionInfo))
            {
                sftpClient.Connect();
                var list = sftpClient.ListDirectory(string.Empty);

                var asynch = sftpClient.BeginUploadFile(File.OpenRead(@"D:\data8.xml"), "small.txt", true, delegate(IAsyncResult ar)
                {
                    Console.WriteLine("callback called");
                    sftpClient.EndUploadFile(ar);
                }, null, (a) =>
                {
                    Console.WriteLine(a);
                }) as SftpUploadAsyncResult;

                Thread.Sleep(1000 * 2);
                asynch.IsUploadCanceled = true;

                asynch.AsyncWaitHandle.WaitOne();
                Console.WriteLine("Finished asynch");
                sftpClient.EndUploadFile(asynch);
                Console.WriteLine("EndUploadFile called");
            }

 

Please check it out and let me know if you have any problems.

 

Thanks,

Oleg

Apr 28, 2015 at 5:30 PM
hi Oleg can you please convert this code to visual basic.net