Asyncronous File Uploads and Downloads with SSH.NET

Sep 5, 2013 at 5:49 PM
Can anyone point me to any good WORKING examples of doing asynchronous file uploads and downloads using this library? The documentation is lacking in this regard, and despite finding a few different (somewhat conflicting) examples of doing it, I'm not having any success.

Right now, I'm opening up a file stream for writing, creating an sftp client, calling BeginDownloadFile with the server filename and my file stream, and then blocking until the operation is complete. I'm starting small here - one file - but the goal is to be able up upload and download multiple files simultaneously.

The issue I'm having is that the client never actually attempts to access the server. I've got the server running locally (FileZilla Server), and I'm watching the console, but I never see a login attempt. However, for whatever reason, the AsyncResult returned from the BeginDownloadFile call is returning true in the IsCompleted property despite never attempting to open the connection.

No errors are being thrown until I attempt to call EndDownloadFile (according the the limited examples I've seen) when the operation is (supposedly) completed.

Any assistance, especially a link to some working code, would be greatly appreciated.

Also, out of curiosity, what is the purpose of the three variants of BeginDownloadFile, especially the two versions that accept callback delegates? It seems, since you're passing in a stream to begin with, that the callbacks aren't all that useful. Also, what exactly does EndDownloadFile actually do? Does it have to be called?

Why utilize a boolean IsCompleted property rather than utilizing WaitHandle.WaitAll() to wait for the completion of multiple threads? I'm just curious why it was designed that way? Performance? Ease of use? Just wondering.