New Post: SftpClient.Exists and SftpClient.DownloadFile CREATE a file on server if file does not exist
New Post: Zlib compression support
Is there a way for client to tell server disabling compression for the connection?
I would be happy to try out if there is an alpha version available. Thanks.
New Post: Strong name
Closed Issue: Orphaned threads when port forwarding [1522]
In the situation where a port forward has been established and actively used, therefore a listener thread has been created, if the network is disconnected (by pulling out the cable) and reconnected sometime later then the internal thread will remain there even after everything else has been disposed properly. This causes problems, especially when trying to exit the application since it will hang.
With a fair amount of Console.WriteLineing it was established that the internal listener thread, consisting mostly of the Bind function in ChannelDirectTcpip, eventually exits its main loop correctly but then stalls at this point forever (well at least until a kill -9 is issued):
```
System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof });
```
I do not know much about the inner workings of SSH.NET and therefore do not know the best solution to the problem, but a workaround that seems to do the job for us is to simply allow that wait to timeout:
```
System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof }, 5000);
```
After that, the inner thread exits properly and no more hangs on exit.
Closed Issue: Process terminated due to unhandled exception in Finalize / Destructor [1514]
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: Renci.SshNet.Common.SshConnectionException
Stack:
at Renci.SshNet.Session.SendMessage(Renci.SshNet.Messages.Message)
at Renci.SshNet.Channels.Channel.SendMessage(Renci.SshNet.Messages.Connection.ChannelCloseMessage)
at Renci.SshNet.Channels.Channel.Close(Boolean)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean)
at Renci.SshNet.Channels.Channel.Dispose(Boolean)
at Renci.SshNet.Channels.ChannelSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SubsystemSession.Finalize()
__This occurred just over 60 seconds _after_ the Dispose method on SftpClient was called which generated a very similar exception (handled and logged by my code):__
2013-02-16 15:41:32.9693 Error SftpFileTransfer Renci.SshNet.Common.SshConnectionException,Client not connected., at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.Channels.Channel.SendMessage(ChannelCloseMessage message)
at Renci.SshNet.Channels.Channel.Close(Boolean wait)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait)
at Renci.SshNet.Channels.Channel.Dispose(Boolean disposing)
at Renci.SshNet.Channels.ChannelSession.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean disposing)
at Renci.SshNet.SftpClient.Dispose(Boolean disposing)
at Renci.SshNet.BaseClient.Dispose()
at BusinessObjects.SftpFileTransfer.DownloadFiles()
__It looks like ~SubsystemSession() is causing an attempt to send a message over the channel(!) due to the chaining of calls to the various Dispose() methods.__
Closed Issue: SCP Can't Upload Rooted Directories [1511]
Closed Issue: Invalid handling of http proxy server response [1509]
I did find a problem when testing the assembly with our squid 3.0 proxy. I receive the message, that Result cannot be called on a failed match. Therefore I've extended the code in Session.cs a little bit:
if (statusCode == 200 && string.IsNullOrEmpty(response))
{
// Once all HTTP header information is read, exit
break;
}
else
{
string reasonPhrase = string.Empty;
try
{
if (match.Success)
reasonPhrase = match.Result("${reasonPhrase}");
}
catch (Exception ex)
{
reasonPhrase = string.Empty;
}
Now the following line
throw new ProxyException(string.Format("HTTP: Status code {0}, Reason \"{1}\"", statusCode, reasonPhrase));
Does at least return the error code (not yet the fault reason; in this case ERR_ACCESS_DENIED)
In fact the code received a 403 status code from the proxy:
SshNet.Logging Verbose: 1 : Initiating connect to 'yyy.xxx.zzz.ww:22'.
HTTP/1.0 403 Forbidden
Server: squid/3.0.STABLE16-RC1
Mime-Version: 1.0
Date: Wed, 13 Feb 2013 14:15:06 GMT
Content-Type: text/html
Content-Length: 1008
Expires: Wed, 13 Feb 2013 14:15:06 GMT
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from app-proxy-3.xxxx.xxx
Via: 1.0 app-proxy-3.xxxx.xxx (squid/3.0.STABLE16-RC1)
Proxy-Connection: close
The thread 0xa2c has exited with code 0 (0x0).
Kind regards
Johannes
Closed Issue: Dispose() should not leave running threads behind! [1436]
Closed Issue: SCP : Missing files when using DirectoryUpload [1382]
Closed Feature: File Transfer Progress [1324]
Closed Issue: Unobserved exception rethrown by finalizer thread [1298]
New Post: Zlib compression support
Commented Issue: Exception thrown on disconnect [1561]
I understand that I could put a try catch around the SshClient.Disconnect call but it seems like the better place for the try catch would be in the session class where the disconnect message is being sent. If an exception is thrown during a disconnect it could just be ignored.
Comments: ** Comment from web user: Mister_Goodcat **
Hi.
I seem to have the same or at least a related problem, however the consequences are a lot more fatal on my end. Scenario here:
* I connect to a remote server to invoke a command that gracefully shuts down the services there and then turns off the device (it's a NAS). That means that the SSH service is shut down on the server side when I'm still connected.
* On the client, I see two things: first of all the callback of the asynchronously executed command is never invoked, which I think is not expected. I would expect the command to finish and throw an exception when I invoke the EndExecute method in my callback. The only possibility to get notified about the disconnect is to hook the ErrorOccurred event on the client.
* When I try to Disconnect() or Dispose() in that event handler, I seem to get the same race condition, however in my case execution simply hangs and never continues (looks like a dead lock to me, haven't looked at the actual code).
This behavior is fatal on my dev machine when I debug my code in Visual Studio 2012: execution hangs as soon as I invoke Disconnect(), and when I then stop debugging (Shift+F5) __Windows 8 crashes with a BSOD__ telling me the process has still locked pages. I could reproduce this behavior three times in a row after clean reboots.
Running the application outside of Visual Studio does not result in a BSOD, however the thread my code executes on simply dies and never recovers until the process is shut down.
I still think your library is an excellent project and would like to thank you for it; if you could fix that problem, it would be perfect for my use case.
-Peter
Commented Issue: Unhandled exception during SftpClient Dispose [1581]
2013-05-13 12:54:22,711 [2] FATAL - AppDomain.UnhandledException
Renci.SshNet.Common.SshConnectionException: Client not connected.
at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.Channels.Channel.Close(Boolean wait)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait)
at Renci.SshNet.Channels.Channel.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean disposing)
at Renci.SshNet.SftpClient.Dispose(Boolean disposing)
at Renci.SshNet.BaseClient.Finalize()
This happens when the connection to the Ssh server is lost and affects our ability to gracefully handle situations when servers/connectivity goes down. O
The solution I suggest to swallow any exceptions coming from SftpClient.Dispose() as follows. Not pretty but as a general rule, Dispose shouldnt be throwing exceptions, unless such exceptions are symtomatic of a more serious problem.
Cheers
protected override void Dispose(bool disposing)
{
try
{
if (this._sftpSession != null)
{
this._sftpSession.Dispose();
this._sftpSession = null;
}
if (this._disposeConnectionInfo)
((IDisposable)this.ConnectionInfo).Dispose();
base.Dispose(disposing);
}
catch
{
// swallow it
}
}
Comments: ** Comment from web user: Mister_Goodcat **
Hi. I think your problem, that of user "pmilin" and mine are similar and/or related, see:
https://sshnet.codeplex.com/workitem/1561
In my case, I am _not_ able to solve the problem with catching exceptions (for details see the above work item).
New Post: ExpectAction Problem
I'm trying to issue a traceroute command on a cisco router without the host specified. This causes the CLI to ask for additional information, including target and source host. A total of 10 questions are asked before the command is successfully executed.
I thought I could just chain ExpectActions as so:
ss.Expect(
new ExpectAction(@"Protocol \[ip\]: ", (s) =>
{
ss.WriteLine("ip");
_reply += s;
}),
new ExpectAction(@"Target IP address: ", (s) =>
{
ss.WriteLine(dIpAddress);
_reply += s;
}),
new ExpectAction(@"Source address: ", (s) =>
{
ss.WriteLine(sIpAddress);
_reply += s;
}),
new ExpectAction(@"Numeric display \[n\]: ", (s) =>
{
ss.WriteLine("n");
_reply += s;
}),
new ExpectAction(@"Timeout in seconds [3]: ", (s) =>
{
ss.WriteLine("3");
_reply += s;
}),
new ExpectAction(@"Probe count [3]: ", (s) =>
{
ss.WriteLine("3");
_reply += s;
}),
new ExpectAction(@"Minimum Time to Live [1]: ", (s) =>
{
ss.WriteLine("1");
_reply += s;
}),
new ExpectAction(@"Maximum Time to Live [30]: ", (s) =>
{
ss.WriteLine("30");
_reply += s;
}),
new ExpectAction(@"Port Number [33434]: ", (s) =>
{
ss.WriteLine("33434");
_reply += s;
}),
new ExpectAction(@"Loose, Strict, Record, Timestamp, Verbose[none]: ", (s) =>
{
ss.WriteLine(" ");
_reply += s;
}),
new ExpectAction(new Regex(@"\\* \\* \\*"), (s) =>
{
_reply = s;
_reply += s;
})
);
However, only the first two are ever processed.I assume I'm doing this wrong. I appreciate any input.
Commented Issue: Exception thrown on disconnect [1561]
I understand that I could put a try catch around the SshClient.Disconnect call but it seems like the better place for the try catch would be in the session class where the disconnect message is being sent. If an exception is thrown during a disconnect it could just be ignored.
Comments: ** Comment from web user: winkledumpling **
I believe this is the same issue as
https://sshnet.codeplex.com/workitem/1581
New Post: Odd reoccurring exception
Application: NodeService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at Renci.SshNet.ShellStream.Channel_DataReceived(System.Object, Renci.SshNet.Common.ChannelDataEventArgs)
at Renci.SshNet.Channels.Channel.OnData(Byte[])
at Renci.SshNet.Channels.Channel.OnChannelData(System.Object, Renci.SshNet.MessageEventArgs`1<Renci.SshNet.Messages.Connection.ChannelDataMessage>)
at Renci.SshNet.Session.OnChannelDataReceived(Renci.SshNet.Messages.Connection.ChannelDataMessage)
at Renci.SshNet.Session.HandleMessage(Renci.SshNet.Messages.Connection.ChannelDataMessage)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Runtime.CompilerServices.CallSite, System.__Canon, System.__Canon)
at Renci.SshNet.Session.HandleMessageCore(Renci.SshNet.Messages.Message)
at Renci.SshNet.Session.MessageListener()
at Renci.SshNet.Session.<Connect>b__4()
at Renci.SshNet.Session+<>c__DisplayClass3d.<ExecuteThread>b__3c(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Machine was running Windows 7 64-bit, with .Net 4.5.
I'll try installing VS on the machine and see if I can get any insight.
thx
Steve
Created Unassigned: Infinite loop in SocketReadLine Method [1582]
Where was an infinite loop ,do {..} while {.. buffer[buffer.Count - 1] == 0x0A ...} condition wasn't true, and a i get exception SshOperationTimeoutException("Socket read operation has timed out"), that was strange, i changed condition to
while (!(buffer.Count > 0 && (buffer[buffer.Count - 1].Equals(0x0A) || buffer[buffer.Count - 1].Equals(0x00) )));
and now everything works great. Thank one more time for your library.
New Post: Pageant integration?
Are there any suggestions for detecting which Pageant build is running and adapting to the API appropriately for this patch?
New Post: ExpectAction Problem
The root cause of my problem was that I didn't realize that WriteLine was sending "\r\n". Cisco routers don't line the linefeed. This had worked with SharpSSH, but it was only sending "\r".
So I changed everything to Write and added the \r to my data. Now everything works.