sshnet / ssh.net Goto Github PK
View Code? Open in Web Editor NEWSSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
License: MIT License
SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
License: MIT License
Hi guys,
I use latest version of SSH.NET (2016.0.0 beta3). I get the following message when my application tries to disconnect from remote server:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: length
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.Renci.SshNet.ISession.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.Channel.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.Channel.Close(Boolean wait)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait)
at Renci.SshNet.Channels.Channel.Close()
at Renci.SshNet.SubsystemSession.Disconnect()
at Renci.SshNet.SftpClient.OnDisconnecting()
at Renci.SshNet.BaseClient.Disconnect()
at DBAService.Logic.FileTransfer.DbaSftpClient.CloseConnection() at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.Renci.SshNet.ISession.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.Channel.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.Channel.Close(Boolean wait)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait)
at Renci.SshNet.Channels.Channel.Close()
at Renci.SshNet.SubsystemSession.Disconnect()
at Renci.SshNet.SftpClient.OnDisconnecting()
at Renci.SshNet.BaseClient.Disconnect()
at DBAService.Logic.FileTransfer.DbaSftpClient.CloseConnection()
Is it related with issue #58 ?
Alex.
Would it be possible to support more crypto algorithms which recent versions of OpenSSH support?
From man ssh_config
on Debian Jessie.
MACs
[email protected],[email protected],
[email protected],[email protected],
[email protected],[email protected],
hmac-sha2-256,hmac-sha2-512,
[email protected],[email protected],
[email protected],
[email protected],[email protected],
hmac-md5,hmac-sha1,hmac-ripemd160,
hmac-sha1-96,hmac-md5-96
Ciphers
aes128-ctr,aes192-ctr,aes256-ctr,
[email protected],[email protected],
[email protected],
arcfour256,arcfour128,
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,
aes192-cbc,aes256-cbc,arcfour
KexAlgorithms
[email protected],
ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,
diffie-hellman-group-exchange-sha256,
diffie-hellman-group14-sha1,
diffie-hellman-group-exchange-sha1,
diffie-hellman-group1-sha1
Related to: darkoperator/Posh-SSH#103
Partly related to: #20
I got the Exception
I can connect sshd server. bat I can't run any command.
An existing connection was forcibly closed by the remote host
//Generate ConnectionInfo for Win32-OpenSSH sshd server (localhost)
var info = GenerateConnectionInfo(name);
var client = new SshClient(info);
//In this timing IsConnected == true
client.Connect();
//Throw!! SshConnectionException
//An existing connection was forcibly closed by the remote host
var cmd = client.RunCommand("dir");
Console.WriteLine(cmd.Result);
For details, you can see this issue on StackOverflow.
When an rpc-reply message is received, this exception is thrown in NetconfSession.OnDataReceived event handler.
The cause is that the received data length is 1015 byte, and the decoded message string contains a magic number at the beginning as below:
#1585
This number is matched with a regex then is used to append this length of data to a stringbuilder, namely to _rpcreply object, like :
var match = Regex.Match(chunk.Substring(position), @"\n#(?<length>\d+)\n");
if (!match.Success)
{
break;
}
var fractionLength = Convert.ToInt32(match.Groups["length"].Value);
_rpcReply.Append(chunk, position + match.Index + match.Length, fractionLength);
where the value of position is the number at the beginning of the message, that is, 1585 in this example.
It is obvious that the Append operation will fail as one can't append 1585 byte from an 1015 byte length string.
What I can't figure out is where this magic number is coming from, as RFC6241 apparently does not contain such - lets call it - segment length element ? So where is it coming from, can anyone tell ?
Hi dear Gert.
I can not run a background task with "&" at the end of the command line. My symbol "&" is simply ignored. Could you help me please?
Cordially Khamzat
Currently the implementation of SynchronizeDirectories from SftpClient uses the size of the file to know if it needs to override it. Unfortunately this is not good enough in most cases. There is a comment about using MD5, which would be nice indeed. In the meantime, could we use a some file stamp comparison?
I try to connect to a Cisco IOS XR router using the below code :
_ncClient = new NetConfClient("10.10.10.1", 830, "admin", "admin");
_ncClient.KeepAliveInterval = TimeSpan.FromSeconds(2);
_ncClient.OperationTimeout = TimeSpan.FromSeconds(60);
_ncClient.ErrorOccurred += ErrorOccurred;
_ncClient.AutomaticMessageIdHandling = false;
_ncClient.Connect();
At first the connection seems to suceed as IsConnected is true, but a second later the ErrorOccured event is fired with a message like : "An establshed connection was aborted by the server"
This happens right after the call to_netConfSession.Connect();
I also checked that SshClient can connect to the same router with no issues, therefore I am sure the underlying SSH transport is workingcorrectly.
Also, the same router accepts Netconf sessions when I use a Python code, so the issue I guess is not related to router configuration.
I have seen some article suggesting this might be related to ClientCapabilities xml as set by NetconfSession constructor, but could not figure out whether this was the problem or not :
ClientCapabilities.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
"<capabilities>" +
"<capability>" +
"urn:ietf:params:netconf:base:1.0" +
"</capability>" +
"</capabilities>" +
"</hello>");
Any ideas please ?
I've been experimenting with the scp implementation and it is slower compared to the command line tool scp. In my test, it is 5s to copy several files with scp, and 33s with SSH.NET. I noticed that most of the time, it was stuck in a Thread.Sleep (100)
in ScpClient.ReadByte
, so I changed this to Thread.Sleep(0)
and it went down to 15s.
I initially reported this on the old codeplex site and as recommended I'm now filling an issue on GitHub.
This is not blocking as I can use sftp instead which is faster.
Thanks!
Hello,
I don't know if its issue or I'm doing something wrong, I starting using older versions of Ssh.net and everything work fine but when I update to the last version I can't connect at server.
System.Net.Sockets.SocketException (0x80004005): Operation Not Supported em System.Net.Sockets.Socket.ConnectAsync(SocketAsyncEventArgs e) em Renci.SshNet.Abstractions.SocketAbstraction.Connect(IPEndPoint remoteEndpoint, TimeSpan connectTimeout) em Renci.SshNet.Session.SocketConnect(String host, Int32 port) em Renci.SshNet.Session.Connect() em Renci.SshNet.BaseClient.Connect()
Code is simple
client = new SshClient("192.168.1.141", "user", "123456"); client.KeepAliveInterval = TimeSpan.FromSeconds(120); client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(150); client.Connect();
I can't find any solution over the web and I don't know what do to.
Anyone can help me?
Thanks!
The ConnectionInfo class makes use of a Timeout property of type TimeSpan that allows for an Int64 constructor parameters upon instantiation. A Developer can either use the default Timeout value of 30 seconds or set their own value up to Int64.MaxValue. However the underlying Socket construct's "SendTimeout" and "RecieveTimeout" only allow for Int32 values. This issue throws an OutOfRangeExeception at runtime when attempting to set the TimeSpan value to a tick value greater than Int32.MaxValue. The maximum value of TimeSpan is designed to allow for 29K years using Int64 values of the 100ns scale, but the underlying Socket's maximum value uses Int32 on the millisecond scale, which is roughly 24 days.
It would be nice if SSH.NET used SecureString for the password in PasswordConnectionInfo for instance.
First of all, big welcome to migrate to GitHub!
The question is, how much effort would take to make a version for UWP? Is it in the team's pipe line?
Best wishes.
Hi, I'm using ShareX software developed by @Jaex and my issue related to it is here: ShareX/ShareX#1797
Jaex is using the SSH.NET library in his software so it allows me uploading images using SFTP then giving me a link to view it publicly. But since 11.2.1 the library got updated and causes images to distort (idk the correct term for this issue) corrupt on upload. See here as an example: http://i.qcfb.ca/20160819033042.png. Also (Thanks @Kiwi-1995 for those as an example haha)
https://chie.club/files/images/st/1819b4c5-4de7-4c93-90d9-e278a57bc8cc.png - Uploaded
https://chie.club/files/images/st/1819b4c5-4de7-4c93-90d9-e278a57bc8c2c.png - The original
(Credit to @Kiwi-1995 - His/Her issue here ShareX/ShareX#1802)
Setting the buffer size higher than 32kb causes this image corruption while using SFTP uploads. I tried lower 32kb, still occurs. Only 32kb fixed our issues (Workaround I've found)
I am using Renci.SsshNet to pull files from a FTP server and process them. This is the method I'm calling to get my file:
private byte[] GetFileFromSFtp(string server, int port, string username, string password, string fileName)
{
byte[] file;
var sftp = new SftpClient(server, port, username, password);
sftp.Connect();
var fileRead = sftp.OpenRead(fileName);
using (var memStream = new MemoryStream())
{
fileRead.CopyTo(memStream);
file = memStream.ToArray();
}
sftp.Disconnect();
return file;
}
This works fine and my application starts processing the file; however, after about 20 seconds, i get a NullReferenceException.
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exception/LM/W3SVC/1/ROOT/TitanApi-1-131146292255812405
<ExceptionType>System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Object reference not set to an instance of an object.</Message><StackTrace> at Renci.SshNet.Sftp.SftpSession.SendMessage(SftpMessage sftpMessage)
at Renci.SshNet.Sftp.SftpSession.SendRequest(SftpRequest request)
at Renci.SshNet.Sftp.SftpSession.RequestClose(Byte[] handle)
at Renci.SshNet.Sftp.SftpFileStream.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SftpFileStream.Finalize()</StackTrace><ExceptionString>System.NullReferenceException: Object reference not set to an instance of an object.
at Renci.SshNet.Sftp.SftpSession.SendMessage(SftpMessage sftpMessage)
at Renci.SshNet.Sftp.SftpSession.SendRequest(SftpRequest request)
at Renci.SshNet.Sftp.SftpSession.RequestClose(Byte[] handle)
at Renci.SshNet.Sftp.SftpFileStream.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SftpFileStream.Finalize()</ExceptionString></Exception></TraceRecord>
The program '[15268] w3wp.exe' has exited with code 0 (0x0).
Any suggestions on what may be causing this or am I not disposing of my code properly?
Any situation that causes both Password and PrivateKey authentication to be attempted (server requires both, password tried first but is wrong, private keys) will throw CreateMessageTypeAlreadyEnabledForOtherMessageException
for message number 60.
The ssh auth spec indicates that SSH_MSG_USERAUTH_PK_OK
and SSH_MSG_USERAUTH_PASSWD_CHANGEREQ
are method specific, so it is ok that they share message number 60. But SshMessageFactory
treats message numbers globally.
Hi,
the constructor of CreateShellStream expects a parameter "terminal name". What is the impact\consequence of this parameter? Is there a valid enumeration I should use?
Hello,
Some times the connection fails, I can see that because I use the Proxifier, but it doens't throw any exceptions in the application, how I monitoring this?
My code for start connection:
private void Connect()
{
client = new SshClient(host, txtUser.Text, txtPassword.Text);
client.KeepAliveInterval = new TimeSpan(0, 0, 30);
client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
client.Connect();
ForwardedPortDynamic port = new ForwardedPortDynamic(portNumber);
client.AddForwardedPort(port);
port.Start();
}
This work fine, but some times it happens what i say.
Thanks a lot.
When calling SftpClient.CreateDirectory when a directory already exists throws an SshException. Is this expected? It would be nice to either not throw or throw a more meaning full error.
Maybe I am looking at things improperly, but I was trying to find a way to support dynamic terminal resizing using SSH.NET as the connection. Naturally the remote endpoint is expecting a window size in order to properly form the console output wrapping, but all the window sizing code in SSH.NET seems to be hidden as internals.
Although you can set the initial size in ShellStream
or Shell
, there are no methods for changing that while a connection is alive and you can't seem to relinquish the ShellStream
and create a new one in the same connection without crashing the whole application.
I am using 2013.4.7 stable.
Running the bellow code on a Cisco ASA result in an forever hang.
using (var client = new SshClient(host, 22, username, password))
{
client.Connect();
var result = client.RunCommand(command);
returnString = result.Result;
client.Disconnect();
}
ShellStream.Read returns immediately with 0 bytes read when no data is available instead of blocking the call.
Consequently the other functions implemented in the parent class Stream
that implement the asynchronous patterns based on the Read function (BeginRead/EndRead, ReadAsync) return also immediately with a 0 byte read instead of being suspended until data is available.
This prevent using correct asynchronous pattern with these functions.
The following modified function waiting on _dataReceived
when no data is available seems to work:
public override int Read(byte[] buffer, int offset, int count)
{
var i = 0;
while (true)
{
lock (_incoming)
{
for (; i < count && _incoming.Count > 0; i++)
{
buffer[offset + i] = _incoming.Dequeue();
}
}
if (i != 0)
return i;
_dataReceived.WaitOne();
}
}
Hello. We are using version 2014.4.6.0 of SSH.NET and ocasionally we receive the error "Message type 80 is not valid". The code 80 really not seems to be a valid SFTP return code, but we are having throuble trying to figure out what may be causing the issue.
It occurs only occasionally, so its very dificult to reproduce it.
Any info that could point us to the right direction is appreciated.
Hi, This is my test results, SharpSSH run each command takes about 20 milliseconds, SSH.NET run each command takes about 100 milliseconds.
Is it possible to improve performance?Thanks!
Is there a way to issue sudo commands via ssh.net when the server has requiretty set? When requiretty is not set, everything works as expected.
Thanks.
In the Linux SSH docs, it says you can get a random remote port by specifying zero.
In this example, I should get a random port from the server and it should be forwarded back to port 80 on my machine"
Me.sshport = New ForwardedPortRemote(IPAddress.Loopback, 0, IPAddress.Loopback, 80)
Me.ssh.AddForwardedPort(Me.sshport)
I don't see anywhere in the code where I can get the remote random port that was assigned. Is there a way to do that?
Are you planning to add an event "Closed" in the class "ShellStream"?
Something like this:
public event EventHandler Closed;
public override void Close()
{
if (_channel != null)
_channel.Close();
base.Close();
}
private void Channel_Closed(object sender, ChannelEventArgs e)
{
if (Closed != null)
{
// Handle event on different thread
ExecuteThread(() => Closed(this, new EventArgs()));
}
}
instead of this:
private void Channel_Closed(object sender, ChannelEventArgs e)
{
// TODO: Do we need to call dispose here ??
Dispose();
}
Previously it was rejected to add paegent support. Code like: https://github.com/dimov-cz/win-sshfs has several good changes. Any plans to re-consider supporting those things? PR could be put together now that it is on GitHub.
Hi All,
I've upgraded dll from 2014.4.6 to 2016.0.0 and I get this message when application tries to change directory on remote server.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestReadDir(Byte[] handle)
at Renci.SshNet.SftpClient.InternalListDirectory(String path, Action1 listCallback) at Renci.SshNet.SftpClient.ListDirectory(String path, Action
1 listCallback)
at DBAService.Logic.FileTransfer.DbaSftpClient.GetCdrAndTrfFiles()
at DBAService.Logic.FileTransfer.FileTransferSession.FileTransferTask() at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestReadDir(Byte[] handle)
at Renci.SshNet.SftpClient.InternalListDirectory(String path, Action1 listCallback) at Renci.SshNet.SftpClient.ListDirectory(String path, Action
1 listCallback)
at DBAService.Logic.FileTransfer.DbaSftpClient.GetCdrAndTrfFiles()
at DBAService.Logic.FileTransfer.FileTransferSession.FileTransferTask()
Alex.
I'm getting an ArgumentOutOfRangeException
from within SshDataStream.ReadBytes
when I execute the following code:
using (var ssh = new SshClient("ip", 22, "usr", "pwd"))
{
ssh.Connect();
IDictionary<Renci.SshNet.Common.TerminalModes, uint> termkvp = new Dictionary<Renci.SshNet.Common.TerminalModes, uint>();
termkvp.Add(Renci.SshNet.Common.TerminalModes.ECHO, 53);
using (var stream = ssh.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp))
using (var sr = new StreamReader(stream))
{
// wait for command promt
var ln = ReadLine(sr, ">");
while ((ln == null) || !ln.EndsWith(">"))
ln = ReadLine(sr, ">");
// send enable
stream.WriteLine("enable");
// wait for password promt
ln = ReadLine(sr, "Password: ");
while ((ln == null) || !ln.Equals("Password: "))
ln = ReadLine(sr, "Password: ");
// send password
stream.WriteLine("enable-pwd");
// wait for command promt
ln = ReadLine(sr, "#");
while ((ln == null) || !ln.EndsWith("#"))
ln = ReadLine(sr, "#");
var commandPromt = ln;
}
ssh.Disconnect();
}
Background: This code is for connecting to a Cisco router. I need privileged access to the router so I send the "enable" command. The router then promts for a password. The router does not echo the password. And I think that's exactly what confuses SshDataStream.ReadBytes
. The problem occurs only after sending the (hidden) password to the router.
Here is the stack trace from the exception:
Renci.SshNet.dll!Renci.SshNet.Common.SshDataStream.ReadBytes(int length) Line 222
Renci.SshNet.dll!Renci.SshNet.Common.SshDataStream.ReadUInt32() Line 173
Renci.SshNet.dll!Renci.SshNet.Common.SshDataStream.ReadString(System.Text.Encoding encoding) Line 198
Renci.SshNet.dll!Renci.SshNet.Common.SshData.ReadString(System.Text.Encoding encoding) Line 267
Renci.SshNet.dll!Renci.SshNet.Common.SshData.ReadNamesList() Line 289
Renci.SshNet.dll!Renci.SshNet.Messages.Transport.KeyExchangeInitMessage.LoadData() Line 146
Renci.SshNet.dll!Renci.SshNet.Common.SshData.Load(byte[] value, int offset) Line 126
Renci.SshNet.dll!Renci.SshNet.Session.LoadMessage(byte[] data, int offset) Line 1642
Renci.SshNet.dll!Renci.SshNet.Session.ReceiveMessage() Line 954
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1791
Renci.SshNet.dll!Renci.SshNet.Abstractions.ThreadAbstraction.ExecuteThread.AnonymousMethod__0(object o) Line 32
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
When I remove the check which causes the exception to be thrown
if (bytesRead < length)
throw new ArgumentOutOfRangeException("length");
from SshDataStream.ReadBytes
, everything works fine.
So I'm wondering: Am I doing something wrong or is this a bug in SSH.NET? Could you remove that check from SshDataStream.ReadBytes
? If not, is there something else you can do to not getting messed up by such a hidden password use-case?
Note that the ReadLine
method I'm using above is a custom one which basically reads from the underlying stream byte by byte. But the problem described above also occured when I experimented with ShellStream.Expect
or ShellStream.ReadLine
. Nevertheless, here is the code of my ReadLine
method, just for reference:
private static string ReadLine(StreamReader stream, params string[] acceptedLineEndings)
{
var ret = "";
var eol = false;
while (!eol)
{
var b = stream.Read();
if (b >= 0)
{
var c = (char)b;
if (c == '\r')
{
}
else if (c == '\n')
{
eol = true;
}
else
{
ret += (char)b;
}
}
else
{
// if no more data and received data ends with a promt char, we return as well
foreach (var le in acceptedLineEndings)
{
if (ret.EndsWith(le))
{
eol = true;
break;
}
}
}
}
return ret;
}
The "SshNet.Logging" Trace Source is only written to in in debug builds. There is a [Conditional("DEBUG")] on the DiagnosticAbstraction.Log() method.
I know that the trace is limited currently but would assume you should be able to turn it on anyway in the distributed NuGet packages.
It worked in the last stable release (2013.4.7).
AFAIK In java socket is interface (or abstract class) and there are SocketFactory conception. This allows to make such pretty things like SSH over HTTPS or add some protocol obfuscation just using decorator pattern.
At client retrospective this allows client application to use tunneling directly (without binding to physical port). I.e. this allows to connect directly to host:ip via ssh tunnel and get input|output streams.
SftpClient.DeleteDirectory
throws an exception (Permission denied
) when directory contains files.
Suggestion: add support for recursive directory removal together with all the files in it, aka rm -rf dir
Would be good if library provide events which allow implement full tracing of the data which going during communications. That's useful for troubleshooting.
I propose that out of necessity, since I have troubles to send down arrow to terminal. Not taking into account my troubles finding correct code for characters, I could not verify that I send data correctly.
I have correct session recorded using Putty, and create similar log using SSH.NET would help me going forward and verify that I done everything correctly.
I will submit pull request with such functionality later on.
/cc: @driesengView
The current project.json specified dependency as 5.2.0, yet the default template for UWP app is 5.1.0. Therefore the two can't work correctly together.
To repro:
1, use VS 2015 update 3 to create a new UWP app, it compiles alright.
2, add SSH.NET in by NuGet, then F6 will give us these errors:
Detected package downgrade: Microsoft.Win32.Primitives from 4.0.1 to 4.0.0
App3 (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.1.0) -> Microsoft.NETCore (>= 5.0.0) -> System.Net.Primitives (>= 4.0.10) -> runtime.win.System.Net.Primitives (>= 4.0.11) -> Microsoft.Win32.Primitives (>= 4.0.1)
App3 (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.1.0) -> Microsoft.Win32.Primitives (>= 4.0.0)
Detected package downgrade: Microsoft.Win32.Primitives from 4.0.1 to 4.0.0
App3 (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.1.0) -> System.Net.Requests (>= 4.0.10) -> System.Net.Primitives (>= 4.0.10) -> runtime.win.System.Net.Primitives (>= 4.0.11) -> Microsoft.Win32.Primitives (>= 4.0.1)
App3 (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.1.0) -> Microsoft.Win32.Primitives (>= 4.0.0)
...
1>------ Build started: Project: App3, Configuration: Debug x86 ------
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
1> App3 -> c:\scratch\App3\App3\bin\x86\Debug\App3.exe
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1692,5): error APPX1101: Payload contains two or more files with the same destination path 'Microsoft.Win32.Primitives.dll'. Source files:
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1692,5): error APPX1101: C:\Users\dong\.nuget\packages\Microsoft.Win32.Primitives\4.0.0\lib\dotnet\Microsoft.Win32.Primitives.dll
...
If we change the UWP app json to 5.2.0, then all those will be gone. But this is probably prohibited for some people/project.
If there is no specific reason to require 5.2.0, can we change it to 5.1.0 so that it works out of box?
Best regards
when can we expect a stable release? been using this for ages and seems pretty stable. most of us need a stable nuget release so our consuming packages can get out of beta too.
`.........
Exception thrown: 'System.NotSupportedException' in Renci.SshNet.dll
System.NotSupportedException: SOCKS version 67 is not supported.
..........`
How to fix these?
NB:
VS2015
Win10
Good day!
Connection to my development server averages for about 12 seconds. Is there any way to make it faster?
Piece of code below, for your reference:
private void Connect() { bool success = true; try { this.client = new SftpClient("xxx.xxx.xxx.xx", "username", "password"); this.client.Connect();//THIS PART TAKES ABOUT 12 SECONDS ON AN AVERAGE } catch (Exception ex) { success = false; ErrorMessage = "SFTP-Connect()|" + ex.Message.ToString(); } }
I'm currently using Parallelism in my console app (Parallel.Foreach, Task.Factory.StartNew) for faster processing, for it reads several files from an SFTP path. But the connection part kills me.
Appreciate your prompt help, I'm currently applying this on my SFTP-related project.
Cheers,
Hi,
Would you consider adding LocalIP (and LocalPort defaulting to 0) property to the ConnectInfo? I have a multi-IP server and need to bind to a particular IP for the SFTP to go thru the firewall.
I know that Socket.Bind is not supported by all target frameworks.
I ended up modifying the ConnectInfo with the two properties, the PasswordConnectionInfo to add the necessary constructors, the Session.SocketConnect to optionally construct an IPEndPoint and the SocketAbstraction.Connect to pass the local EndPoint and do a socket.Bind.
I used FEATURE_SOCKET_SYNC to surround the socket.Bind to make the code compile.
Of course this is a hack for my needs only.
Basic Issue: Some Cisco IOS, in my case 3600 switch, throws an error just after the password is sent. I support 4 models today, 800, 3600, 1921 and 3600. Using the same code, all but the 3600 works. This is consistent across several 3600 models. From a layman's perspective, I think the issue is in the ShellStream area. Also, watching wireshark, I do not see the connection dropping (red [RST,ACK]).
Another point, if I send the wrong password or time out, either case the shell sends an error, the channel is not dropped.
Have tested previous version from NuGet, with pulling down the 2016.0.0 source. All examples are using the 2016.0.0 source.
I have included code and debug from both successful and unsuccessful attempts. They are the same to channel 3. In the unsuccessful example the error is thrown, in successful there is more channel dialog.
If I trap on the catch for the Session.MessageListener(), I get the following trace
at Renci.SshNet.Common.SshDataStream.ReadBytes(Int32 length) in C:\Renci.SshNet\Renci\Renci.SshNet\Common\SshDataStream.cs:line 223
at Renci.SshNet.Common.SshDataStream.ReadBinary() in C:\Renci.SshNet\Renci\Renci.SshNet\Common\SshDataStream.cs:line 105
at Renci.SshNet.Common.SshData.ReadBinary() in C:\Renci.SshNet\Renci\Renci.SshNet\Common\SshData.cs:line 278
at Renci.SshNet.Messages.Transport.IgnoreMessage.LoadData() in C:\Renci.SshNet\Renci\Renci.SshNet\Messages\Transport\IgnoreMessage.cs:line 61
at Renci.SshNet.Common.SshData.Load(Byte[] value, Int32 offset) in C:\Renci.SshNet\Renci\Renci.SshNet\Common\SshData.cs:line 126
at Renci.SshNet.Session.LoadMessage(Byte[] data, Int32 offset) in C:\Renci.SshNet\Renci\Renci.SshNet\Session.cs:line 1642
at Renci.SshNet.Session.ReceiveMessage() in C:\Renci.SshNet\Renci\Renci.SshNet\Session.cs:line 954
at Renci.SshNet.Session.MessageListener() in C:\Renci.SshNet\Renci\Renci.SshNet\Session.cs:line 1791
Here is my hello world code ......
PasswordConnectionInfo connInfo = new PasswordConnectionInfo("x.x.x.2", "username", "password"); //store 1 switch (3600) //PasswordConnectionInfo connInfo = new PasswordConnectionInfo("x.x.x.1", "username", "password"); //store 1 router (800) //PasswordConnectionInfo connInfo = new PasswordConnectionInfo("x.x.x.2", "username", "password"); //store 286 switch (2960) //PasswordConnectionInfo connInfo = new PasswordConnectionInfo("x.x.x.1", "username", "password"); //store 286 router (1921) SshClient sshClient = new SshClient(connInfo); sshClient.Connect(); ShellStream tmpStream = sshClient.CreateShellStream("Cisco", 80, 24, 800, 600, 1024); StreamReader _reader = new StreamReader(tmpStream); StreamWriter _writer = new StreamWriter(tmpStream); _writer.AutoFlush = true; _writer.Write("en\r"); Thread.Sleep(1000); string tmp = _reader.ReadToEnd(); Console.WriteLine(tmp); Console.WriteLine(sshClient.IsConnected.ToString()); Console.WriteLine("Sending en pass\r\n"); _writer.Write("enPass\r"); Console.WriteLine("Sent en pass\r\n"); Console.WriteLine(sshClient.IsConnected.ToString()); Thread.Sleep(5000); Console.WriteLine(sshClient.IsConnected.ToString()); tmp = _reader.ReadToEnd(); Console.WriteLine(tmp);
Seccessfull example
'MyTest.vshost.exe' (CLR v4.0.30319: MyTest.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SshNet.Logging Verbose: 1 : Initiating connect to 'x.x.x.x:22'.
SshNet.Logging Verbose: 1 : Server version '2.0' on 'Cisco-1.25'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
'MyTest.vshost.exe' (CLR v4.0.30319: MyTest.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyTest.vshost.exe' (CLR v4.0.30319: MyTest.vshost.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhInitMessage': 'SSH_MSG_KEXDH_INIT'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhReplyMessage': 'SSH_MSG_KEXDH_REPLY'.
SshNet.Logging Verbose: 1 : SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessagePassword': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
The thread 0x2568 has exited with code 0 (0x0).
The thread 0x2ba4 has exited with code 0 (0x0).
The program '[5908] MyTest.vshost.exe' has exited with code 0 (0x0).
Unsuccessful example
'MyTest.vshost.exe' (CLR v4.0.30319: MyTest.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SshNet.Logging Verbose: 1 : Initiating connect to '10.5.65.2:22'.
SshNet.Logging Verbose: 1 : Server version '2.0' on 'Cisco-1.25'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
'MyTest.vshost.exe' (CLR v4.0.30319: MyTest.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyTest.vshost.exe' (CLR v4.0.30319: MyTest.vshost.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhInitMessage': 'SSH_MSG_KEXDH_INIT'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhReplyMessage': 'SSH_MSG_KEXDH_REPLY'.
SshNet.Logging Verbose: 1 : SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessagePassword': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #3'.
Exception thrown: 'System.ArgumentOutOfRangeException' in Renci.SshNet.dll
The thread 0x20a8 has exited with code 0 (0x0).
The thread 0x2298 has exited with code 0 (0x0).
The program '[10480] MyTest.vshost.exe' has exited with code 0 (0x0).
Please consider adding support for ed25519 private keys.
We are using the develop branch of your code.
We are using SSH.NET in a command line application. It works fine on windows but when we build it on linux with .net core we get this error message:
SSH.NET-develop/src/Renci.SshNet.NETCore/error CS0041: Unexpected error writing debug information -- 'Windows PDB writer is not available -- could not find Microsoft.DiaSymReader.Native.amd64.dll'
Hello,
After connection with SSH.NET, i can pass all packages from any .exe (ex: chrome.exe, csgo.exe etc) through proxy socks5? Or any have a idea how make this? (Something equal Proxifier)
Sorry for bad english.
Thanks a lot.
The scp Upload
method overload using the file stream does not work correctly. The idiom
using (Stream stm = ...) {
scpClient.Upload(stm, fileName);
}
always fails with a timeout exception.
Stepping through the source, it appears that the channel never gets correctly set up, and it times out while waiting for server's window adjustment message that never arrives.
The ScpClient.Upload(FileInfo, string)
overload, on the other hand, works correctly. (As witnessed by the unit test).
The existing host resolve will always take the first IPAddress which is returned.
We have the situation where the ip address needs to be a IPv4 address since the SFTP server is only bound to the 4 address, however the server also has a IPv6 address.
In some cases there may be times when there will be two addresses of the same type that also need to be decided against.
SftpClient.Exists is supposed to be used for testing for file existence but internally causes an exception to be thrown when a file doesn't exist, which is inefficient and makes debugging etc. a bit painful.
Hi guys,
I use latest version of SSH.NET (2016.0.0 beta3). I get the following message and stack flow when my application tries to disconnect from remote server:
System.NotSupportedException: Data longer than 2147483647 is not supported.
at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestReadDir(Byte[] handle)
at Renci.SshNet.SftpClient.InternalListDirectory(String path, Action1 listCallback) at Renci.SshNet.SftpClient.ListDirectory(String path, Action
1 listCallback)
at DBAService.Logic.FileTransfer.DbaSftpClient.GetCdrAndTrfFiles()
at DBAService.Logic.FileTransfer.FileTransferSession.FileTransferTask() at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestReadDir(Byte[] handle)
at Renci.SshNet.SftpClient.InternalListDirectory(String path, Action1 listCallback) at Renci.SshNet.SftpClient.ListDirectory(String path, Action
1 listCallback)
at DBAService.Logic.FileTransfer.DbaSftpClient.GetCdrAndTrfFiles()
at DBAService.Logic.FileTransfer.FileTransferSession.FileTransferTask()
Remote server contains txt files which size <5M
Alex.
I see that you are starting to use the new corefx libraries but only target UWP at the moment. Have you considered adding additional "netstandard" targets?
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.