johnthegr8 / renci.sshnet.async Goto Github PK
View Code? Open in Web Editor NEWExtends Renci.SshNet to implement the task-based async pattern
License: MIT License
Extends Renci.SshNet to implement the task-based async pattern
License: MIT License
The async methods do not expose CancellationToken parameter.
Since the underlying methods do have access to AsyncCallback, perhaps it would be possible to cancel the upload/download operation in progress?
Hey
Firstly, thank for creating the library, really easy to use.
Wondering if I'm missing something, is there a way to do DeleteAsync?
Thanks
Applications targeting .NET Framework 471 and are strongly named fails to load Renci.SshNet.Async.
Could not load file or assembly 'Renci.SshNet.Async, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required.
Hello. First of all, thanks for share this code.
I'm trying to connect multi sftp client and transfer files, but after connecting 7th client, following exceptions are occurred continuously.
Here is code what I'm using
async Task myTask()
{
using (var ftp = new SftpClient(hostName, userName, passWord))
{
ftp.Connect();
List<Task> uploader = new List<Task>();
ftp.KeepAliveInterval = TimeSpan.FromMinutes(1);
if (ftp.Exists("tmp") == false)
ftp.CreateDirectory("tmp");
foreach (var info in infos)
{
if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
continue;
uploader.Add(Task.Run(async () =>
{
using (Stream fileStream = new FileStream(info.FullName, FileMode.Open))
await ftp.UploadAsync(fileStream, "tmp/" + info.Name);
}));
}
await Task.WhenAll(uploader);
}
}
And here is exceptions I've met
Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out
at Renci.SshNet.Common.AsyncResult.EndInvoke () [0x00035] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.SftpClient.EndUploadFile (System.IAsyncResult asyncResult) [0x0001d] in <3958172c0ff546da829fbc81177cf6a9>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in <567df3e0919241ba98db88bec4c6696f>:0
Renci.SshNet.Common.SshConnectionException: The connection was closed by the server: data packet referred to nonexistent channel 0 (ProtocolError).
at Renci.SshNet.Session.WaitOnHandle (System.Threading.WaitHandle waitHandle, System.TimeSpan timeout) [0x00041] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Session.Renci.SshNet.ISession.WaitOnHandle (System.Threading.WaitHandle waitHandle) [0x0000d] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Channels.Channel.WaitOnHandle (System.Threading.WaitHandle waitHandle) [0x00000] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Channels.Channel.GetDataLengthThatCanBeSentInMessage (System.Int32 messageLength) [0x00051] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Channels.Channel.SendData (System.Byte[] data, System.Int32 offset, System.Int32 size) [0x0000d] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Channels.Channel.SendData (System.Byte[] data) [0x00000] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.SubsystemSession.SendData (System.Byte[] data) [0x0000c] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Sftp.SftpSession.SendMessage (Renci.SshNet.Sftp.SftpMessage sftpMessage) [0x00007] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Sftp.SftpSession.SendRequest (Renci.SshNet.Sftp.Requests.SftpRequest request) [0x00028] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.Sftp.SftpSession.RequestWrite (System.Byte[] handle, System.UInt64 serverOffset, System.Byte[] data, System.Int32 offset, System.Int32 length, System.Threading.AutoResetEvent wait, System.Action`1[T] writeCompleted) [0x00042] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.SftpClient.InternalUploadFile (System.IO.Stream input, System.String path, Renci.SshNet.Sftp.Flags flags, Renci.SshNet.Sftp.SftpUploadAsyncResult asyncResult, System.Action`1[T] uploadCallback) [0x000cc] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.SftpClient+<>c__DisplayClass46_0.<BeginUploadFile>b__0 () [0x00000] in <3958172c0ff546da829fbc81177cf6a9>:0
Renci.SshNet.Common.SshConnectionException: Client not connected.
at Renci.SshNet.Common.AsyncResult.EndInvoke () [0x00035] in <3958172c0ff546da829fbc81177cf6a9>:0
at Renci.SshNet.SftpClient.EndUploadFile (System.IAsyncResult asyncResult) [0x0001d] in <3958172c0ff546da829fbc81177cf6a9>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in <567df3e0919241ba98db88bec4c6696f>:0
Many thanks for reading
If possible, I think a ConnectAsync() method would be very useful. Currently, when a client is trying and failing to connect to a server, the Connect() method lasts several seconds and thus freezes the app that it is in. Adding an asynchronous connection method would allow apps to establish SSH or SFTP connections without holding up the UI thread.
On the release page for SSH.NET 2020.0.0 it states:
SSH.NET now supports the following additional key exchange algorithms:
- curve25519-sha256
- [email protected]
- ecdh-sha2-nistp256
- ecdh-sha2-nistp384
- ecdh-sha2-nistp521
- diffie-hellman-group14-sha256
- diffie-hellman-group16-sha512
There are already a lot of SSH servers that don't accept the old algorithms anymore.
If you can verify that Renci.SshNet.Async works with the newer version of SSH.NET, this would hopefully prevent other software from accidently importing the older version.
Thanks,
Mathias
now only upload and download has async method, not found in deletefile, hope to add it
The dependency of SSH.net being used is 2016.1.0. There is a known issue around disposing when trying to disconnect. Should this code base downgrade the SSH.NET dependency to 2016.0.0? Here is the issue - sshnet/SSH.NET#355
Post Sample download file!
Hi,
I am getting following exceptions:
System.MissingMethodException: Default constructor not found for type Renci.SshNet.Security.KeyExchangeDiffieHellmanGroupExchangeSha256
at Renci.SshNet.Session.WaitOnHandle (System.Threading.WaitHandle waitHandle, System.TimeSpan timeout) [0x00041] in :0
at Renci.SshNet.Session.WaitOnHandle (System.Threading.WaitHandle waitHandle) [0x0000d] in :0
at Renci.SshNet.Session.Connect () [0x00246] in :0
at Renci.SshNet.BaseClient.Connect () [0x00077] in :0
at PackingPhotosTransfer.MainPage.SaveImages (System.Object sender, System.EventArgs e) [0x00153] i
{System.InvalidOperationException: Invalid response.
at Renci.SshNet.Common.AsyncResult.EndInvoke () [0x00035] in :0
at Renci.SshNet.SftpClient.EndUploadFile (System.IAsyncResult asyncResult) [0x0001d] in :0
at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func
2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task
1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs:538
--- End of stack trace from previous location where exception was thrown ---
When running the following code, a deadlock occurs when trying to disconnect from the server:
class Program
{
static void Main(string[] args)
{
using var sftpClient = new SftpClient("localhost", 22, "user", "password");
sftpClient.Connect();
sftpClient.WriteAllText("test.txt", "blah", Encoding.UTF8);
}
}
The server this was ran against was a docker container using the following command:
docker run --rm -it -p 22:22 atmoz/sftp user:password:::
MacOS
.NET Core 3.1
The above snippet of code works fine with v1.2.0 of Renci.SshNet.Async.
Deeply missed...
Trying to leverage from an Azure function with the following code
Receiving the following error when trying to connect
Here is how my project is setup
Pulled in a coworker to take a look and he noticed that an old assembly was being included, Renci.SshNet.Async was pulling in SSH.NET 2016.1.0. We installed SSH.NET 2024.0.0 and our connection issues cleared up. Without 2024.0.0 installed, the client will not connect.
Hopefully this helps someone else
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.