-
-
Notifications
You must be signed in to change notification settings - Fork 947
Add support for a Task based async API #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think if public SshCommand EndExecute(IAsyncResult asyncResult) then we could do: public static Task<SshCommand> RunCommandAsync(this SshClient sshClient, string command)
{
if (sshClient == null)
throw new ArgumentNullException(nameof(sshClient));
var sshCmd = sshClient.CreateCommand(command);
return Task<SshCommand>.Factory.FromAsync(sshCmd.BeginExecute, sshCmd.EndExecute, null);
} and then |
In the extension method I posted above, if you replace My workaround right now is the following: public static async Task<SshCommand> RunCommandAsync(this SshClient sshClient, string commandText)
{
if (sshClient == null)
throw new ArgumentNullException(nameof(sshClient));
return await Task.Run(() => sshClient.RunCommand(commandText)).ConfigureAwait(false);
} |
…existing async API for SftpClient. Added into a new project targeting .net 4.5.
Maybe the library will get the TAP support. If it is not, there is also a nuget package Rehci.SshNet.Async. |
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... |
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. |
…existing async API for SftpClient. (Not supported by .net 3.5)
The |
The proposed |
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. |
@andriysavin, I agree regarding SftpClient. |
@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? |
@drieseng, we are running into the issues with |
I just added ConnectAsync to the PR. I believe the functionality should now be functionally complete for most uses. |
@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. |
@drieseng pinging you again in case you missed the above proposal |
@IgorMilavec Sorry man, I've been very busy the last months (or is it years). I'll try to find more time. |
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...The text was updated successfully, but these errors were encountered: