You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'll make the library much easier to use with async/await and fit the modern .NET async friendly way of working.
I'd suggest at minimum the following methods:
public Task<Stream> DownloadFileAsync(string path)
public Task<IEnumerable<SftpFile>> ListDirectoryAsync(string path)
public Task UploadFileAsync(string path, Stream stream, bool overwrite = false)
I've managed to wrap the old IAsyncResult style API you already have for DownloadFile as follows:
await Task.Factory.FromAsync(this.sftpClient.BeginDownloadFile(remoteUri, stream), this.sftpClient.EndDownloadFile) but I'm struggling to figure out the way to do the same for ListDirectory...
Reacted by Vivien S, Jake Rote, Andreas Huber, Omid K. Rad, Adam Voss, Nicholas Mayne, vitidev, Doods, Brian Vallelunga, Sergey Shenets and 25 more
In the extension method I posted above, if you replace Task<SshCommand> with Task<string> it will work, however, since return type isn't SshCommand we can't examine if the command was a success or failure.
It would be really great to only support async going forward for all operations like getting meta data, listing directories, uploading, downloading and seeing if a file or folder exists.
Reacted by Omid K. Rad, Leftyx, kdcllc and Evgeni Nabokov
The proposed ListDirectoryAsync method could make use of IAsyncEnumerable which is new in C# 8.0, but it requires .NET Standard 2.1 or later.
The need of targeting .NET Standard 2.1 is not the biggest impediment for these APIs (cross-compiling could be used for that). The whole library seems to be written without async in mind and requires significant refactoring. All current async methods and wrappers are based on the old Begin/End async pattern, implementation of which turns out to be not really asynchronous and just calls synchronous methods on thread pool threads. This is a well-known antipattern and leads to many problems.
@drieseng I have committed my attempt at implementing DownloadFileAsync in IgorMilavec/SSH.NET@f510968. Can you please have a look and let me know if this is something you would consider merging into SSH.NET, before I push on with other functions as suggested in this issue?
The implementation is async all the way down, no threads were harmed during implementation of this feature. :)
@drieseng can you please have a look at #819? Is it possible to merge this PR and build a beta package? I'm running this code in production on a couple of servers for a month now and did not see any regressions. By building a beta package we would make this more accessible to interested parties and get feedback on code quality and supported usage cases.
Reacted by kdcllc, Arnaud Marant, ChiefWiggum and Kristian Wedberg
Activity
omidkrad commentedon Mar 30, 2017
I think if
SshCommand.EndExecutereturned the command, instead of string, as in:then we could do:
and then
awaiton it.omidkrad commentedon Mar 30, 2017
In the extension method I posted above, if you replace
Task<SshCommand>withTask<string>it will work, however, since return type isn'tSshCommandwe can't examine if the command was a success or failure.My workaround right now is the following:
Fix sshnet#153 support of Task-based Asynchronous Pattern (TAP) over …
bartizan commentedon Sep 15, 2017
Maybe the library will get the TAP support. If it is not, there is also a nuget package Rehci.SshNet.Async.
JohnTheGr8 commentedon Oct 12, 2017
I have updated the aforementioned Rehci.SshNet.Async package to also target .NET Standard 1.3 and UAP.
Hopefully it is useful to some of you...
niemyjski commentedon Feb 23, 2018
It would be really great to only support async going forward for all operations like getting meta data, listing directories, uploading, downloading and seeing if a file or folder exists.
Fix sshnet#153 support of Task-based Asynchronous Pattern (TAP) over …
wplong11 commentedon May 4, 2020
The
Connectmethod must also support asynchronous APIs.vanillajonathan commentedon Feb 22, 2021
The proposed
ListDirectoryAsyncmethod could make use ofIAsyncEnumerablewhich is new in C# 8.0, but it requires .NET Standard 2.1 or later.andriysavin commentedon Feb 23, 2021
The need of targeting .NET Standard 2.1 is not the biggest impediment for these APIs (cross-compiling could be used for that). The whole library seems to be written without async in mind and requires significant refactoring. All current async methods and wrappers are based on the old Begin/End async pattern, implementation of which turns out to be not really asynchronous and just calls synchronous methods on thread pool threads. This is a well-known antipattern and leads to many problems.
IgorMilavec commentedon Mar 10, 2021
@andriysavin, I agree regarding SftpClient.
Hovever, SftpSession's BeginX/EndX implementation looks OK to me on first sight.
IgorMilavec commentedon Mar 11, 2021
@drieseng I have committed my attempt at implementing DownloadFileAsync in IgorMilavec/SSH.NET@f510968. Can you please have a look and let me know if this is something you would consider merging into SSH.NET, before I push on with other functions as suggested in this issue?
The implementation is async all the way down, no threads were harmed during implementation of this feature. :)
kdcllc commentedon May 10, 2021
@drieseng, we are running into the issues with
iasyncresultand can use this feature. Is the PR @IgorMilavec completed?IgorMilavec commentedon May 11, 2021
I just added ConnectAsync to the PR. I believe the functionality should now be functionally complete for most uses.
IgorMilavec commentedon Jun 28, 2021
@drieseng can you please have a look at #819? Is it possible to merge this PR and build a beta package? I'm running this code in production on a couple of servers for a month now and did not see any regressions. By building a beta package we would make this more accessible to interested parties and get feedback on code quality and supported usage cases.
IgorMilavec commentedon Aug 18, 2021
@drieseng pinging you again in case you missed the above proposal
drieseng commentedon Aug 18, 2021
@IgorMilavec Sorry man, I've been very busy the last months (or is it years). I'll try to find more time.