Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Cancel a SFTP upload or download

$
0
0

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


Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>