Source code checked in, #35481
Commented Unassigned: various System.ObjectDisposedException [1944]
```
System.ObjectDisposedException: Das SafeHandle wurde geschlossen.
bei Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Session.cs:Zeile 642.
bei Renci.SshNet.Channels.Channel.WaitHandle(WaitHandle waitHandle) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Channels\Channel.cs:Zeile 496.
bei Renci.SshNet.Channels.ChannelSession.Open() in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Channels\ChannelSession.cs:Zeile 52.
bei Renci.SshNet.ShellStream..ctor(Session session, String terminalName, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, Int32 maxLines, IDictionary`2 terminalModeValues) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\ShellStream.cs:Zeile 73.
bei Renci.SshNet.SshClient.CreateShellStream(String terminalName, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, Int32 bufferSize, IDictionary`2 terminalModeValues) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\SshClient.cs:Zeile 384.
bei Renci.SshNet.SshClient.CreateShellStream(String terminalName, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, Int32 bufferSize) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\SshClient.cs:Zeile 366.
```
and
```
System.ObjectDisposedException: Das SafeHandle wurde geschlossen.
bei System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
bei Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
bei System.Threading.EventWaitHandle.Set()
bei Renci.SshNet.ShellStream.Channel_DataReceived(Object sender, ChannelDataEventArgs e) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\ShellStream.cs:Zeile 739.
bei Renci.SshNet.Channels.Channel.OnData(Byte[] data) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Channels\Channel.cs:Zeile 289.
bei Renci.SshNet.Channels.Channel.OnChannelData(Object sender, MessageEventArgs`1 e) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Channels\Channel.cs:Zeile 590.
bei System.EventHandler`1.Invoke(Object sender, TEventArgs e)
bei Renci.SshNet.Session.OnChannelDataReceived(ChannelDataMessage message) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Session.cs:Zeile 1392.
bei Renci.SshNet.Session.HandleMessage(ChannelDataMessage message) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Session.cs:Zeile 1034.
bei CallSite.Target(Closure , CallSite , Session , Object )
bei Renci.SshNet.Session.HandleMessageCore(Message message) in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Session.NET40.cs:Zeile 20.
bei Renci.SshNet.Session.MessageListener() in c:\Users\srinkes\Desktop\Projects\XXX\Renci.SshNet\Session.cs:Zeile 1589.
```
The application opens a ssh connection and opens/parses a ShellStream every 10 seconds.
IsConnected stays true.
I currently can't test the current beta since it has issues with closing the channel after
disposing the ShellStream.
No errors or unusual log entries on the server side.
Comments: ** Comment from web user: drieseng **
I committed the changes to improve accuracy of IsConnected.
I'd really appreciate it if you could run your tests again.
Note that I backed off on the move to async socket receive as it did not contribute to resolving this issue.
Thanks!
Commented Unassigned: System.ObjectDisposedException at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured [1942]
I have been using the SSH.Net library to connect to a remote SSH server to establish a DB connection between a VB client software and MySQL server. Everything works fine except sometimes the following exception is unhandled and crashes the application:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
at Microsoft.Win32.Win32Native.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle)
at System.Threading.EventWaitHandle.Set()
at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured(System.Exception)
at Renci.SshNet.Channels.Channel.Session_ErrorOccured(System.Object, Renci.SshNet.Common.ExceptionEventArgs)
at System.EventHandler`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Invoke(System.Object, System.__Canon)
at Renci.SshNet.Session.RaiseError(System.Exception)
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()
I am running with the code base downloaded on March 16th 2014.
My connect, disconnect code is pretty straightforward:
client = Nothing
client = New SshNet.SshClient(_host, _port, _user, key)
client.Connect()
portfw = Nothing
portfw = New SshNet.ForwardedPortLocal("localhost", 33306, "localhost", 3306)
client.AddForwardedPort(portfw)
portfw.Start()
...................
If isStarted Then
portfw.Stop()
End If
If isConnected Then
client.RemoveForwardedPort(portfw)
client.Disconnect()
End If
I looked through the issues list and it seems very similar to issue #1840 behaviour...
This seems to happen when the SshNet.SshClient is set to Nothing and disposed, i.e., Create SshClient, connect, create portFW, start, do some operations, stop portFW, remove portFW, disconnect SshClient, Set SshClient to Nothing.
Sometimes, this will result in the exception above.
Many thanks and cheers,
Phil
Comments: ** Comment from web user: drieseng **
Hello Phil,
Could you try using SSH.NET built from SVN ?
Thanks!
Gert
Commented Unassigned: System.ObjectDisposedException at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured [1942]
I have been using the SSH.Net library to connect to a remote SSH server to establish a DB connection between a VB client software and MySQL server. Everything works fine except sometimes the following exception is unhandled and crashes the application:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
at Microsoft.Win32.Win32Native.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle)
at System.Threading.EventWaitHandle.Set()
at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured(System.Exception)
at Renci.SshNet.Channels.Channel.Session_ErrorOccured(System.Object, Renci.SshNet.Common.ExceptionEventArgs)
at System.EventHandler`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Invoke(System.Object, System.__Canon)
at Renci.SshNet.Session.RaiseError(System.Exception)
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()
I am running with the code base downloaded on March 16th 2014.
My connect, disconnect code is pretty straightforward:
client = Nothing
client = New SshNet.SshClient(_host, _port, _user, key)
client.Connect()
portfw = Nothing
portfw = New SshNet.ForwardedPortLocal("localhost", 33306, "localhost", 3306)
client.AddForwardedPort(portfw)
portfw.Start()
...................
If isStarted Then
portfw.Stop()
End If
If isConnected Then
client.RemoveForwardedPort(portfw)
client.Disconnect()
End If
I looked through the issues list and it seems very similar to issue #1840 behaviour...
This seems to happen when the SshNet.SshClient is set to Nothing and disposed, i.e., Create SshClient, connect, create portFW, start, do some operations, stop portFW, remove portFW, disconnect SshClient, Set SshClient to Nothing.
Sometimes, this will result in the exception above.
Many thanks and cheers,
Phil
Comments: ** Comment from web user: ambientson **
Hi Gert,
I will try to get around to it shortly but I was not able to replicate that defect on a consistent basis.
Also, this is something that I worked around by keeping a handle on my connection object during the entire time my application is running (disposing only on exit).
Since my application is stable right now, I am not too keen on upgrading my SSH.NET version. Is the latest SVN build stable? How close are you to a new official release?
I'll revert to the old code and do a few tests and let you know.
Thanks,
Phil
New Post: SSH-2 private key
Please submit an issue for this.
Thanks!
New Post: Unable to read documentation
I downloaded the latest version available.
Still same error please help me.
Thank you.
Avinash
New Post: Unable to read documentation
Can you copy/paste the URL(s) you are having trouble reaching?
New Post: SSH-2 private key
Are you using single-line or multi-line comments ?
Once you submit the issue, I'll commit the fix.
Deal ? :-)
Commented Unassigned: System.ObjectDisposedException at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured [1942]
I have been using the SSH.Net library to connect to a remote SSH server to establish a DB connection between a VB client software and MySQL server. Everything works fine except sometimes the following exception is unhandled and crashes the application:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
at Microsoft.Win32.Win32Native.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle)
at System.Threading.EventWaitHandle.Set()
at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured(System.Exception)
at Renci.SshNet.Channels.Channel.Session_ErrorOccured(System.Object, Renci.SshNet.Common.ExceptionEventArgs)
at System.EventHandler`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Invoke(System.Object, System.__Canon)
at Renci.SshNet.Session.RaiseError(System.Exception)
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()
I am running with the code base downloaded on March 16th 2014.
My connect, disconnect code is pretty straightforward:
client = Nothing
client = New SshNet.SshClient(_host, _port, _user, key)
client.Connect()
portfw = Nothing
portfw = New SshNet.ForwardedPortLocal("localhost", 33306, "localhost", 3306)
client.AddForwardedPort(portfw)
portfw.Start()
...................
If isStarted Then
portfw.Stop()
End If
If isConnected Then
client.RemoveForwardedPort(portfw)
client.Disconnect()
End If
I looked through the issues list and it seems very similar to issue #1840 behaviour...
This seems to happen when the SshNet.SshClient is set to Nothing and disposed, i.e., Create SshClient, connect, create portFW, start, do some operations, stop portFW, remove portFW, disconnect SshClient, Set SshClient to Nothing.
Sometimes, this will result in the exception above.
Many thanks and cheers,
Phil
Comments: ** Comment from web user: drieseng **
The timing for releasing the next stable depends on whether I can consider this regression fixed or now.
It'd be great if you could use the latest SVN build.
I consider it more stable than the latest beta, and - unless new regressions are discovered - this will be very close to the next official release (although I may release another beta first).
New Post: Timeout establishing SSH sessions
Does anyone know of a way to specify a timeout on SSH.NET calls? If necessary I could re-write the script as a C# executable although I would prefer to keep this as a Powershell script if possible.
Thanks.
New Post: Unable to read documentation
I have attached a file have a look.
I downloaded “SshNet.Help.chm” which ever tab[link] I choose I get the same error.
-Avinash
New Post: Unable to read documentation
mk:@MSITStore:C:\Users\AA031791\Downloads\SshNet.Help%20(1).chm::/html/379fc93d-55b9-e3c8-673c-e8f71ad64ca3.htm Is this the URL you told me to paste.!
Sorry i tried uploading snap shot so, that you get exact problem, but not able to load from local pc.
New Post: Timeout establishing SSH sessions
What version of SSH.NET are you using ?
Could you try using the latest beta ?
A timeout can be specified on two levels. For estabilishing the connection, the timeout can be specified using the ConnectionInfo.Timeout property. The default value is 30 seconds.
For all other operations, the timeout can be set using the OperationTimeout property on the individual client classes (eg. SftpClient, SshClient).
Hope this helps,
Gert
Commented Unassigned: How to read linux cmd output all lines [1963]
I am using SSH.Net library to connect linux server and executing some cmds. I am trying to read the out put of the command like below.. but it is returning only first row of the result. If I ran the same cmd in linux directly i will get multiple rows result. Please help to fix my code.
```
var cmd = ssh.CreateCommand("mycmd"); //It is a linux shell script it ran and gives output
var asynch = cmd.BeginExecute(delegate(IAsyncResult ar)
{
Response.Write("Finished.");
}, null);
var reader = new StreamReader(cmd.OutputStream);
while (!asynch.IsCompleted)
{
var result = reader.ReadLine();
Response.Write(result);
if (string.IsNullOrEmpty(result))
continue;
}
cmd.EndExecute(asynch);
```
Comments: ** Comment from web user: drieseng **
Please provide a small self-contained repro (including shell script) that allows me to reproduce this issue.
Thanks!
New Post: Timeout establishing SSH sessions
Invoke-SshCommand : Exception calling "RunCommand" with "1" argument(s): "Session operation has timed out"
with any commands im trying to execute
using the latest beta
Gregor
New Post: Setting transfer mode to binary
ConnectionInfo info = new PasswordConnectionInfo(host, user, pwd);
List<SftpFile> lst;
using(SftpClient objSftp = new SftpClient(info))
{
objSftp.Connect();
lst = objSftp.ListDirectory(strSrc).ToList();
foreach (SftpFile file in lst)
{
if (!file.IsDirectory)
{
if (file.Name == "Test_Record.wav")
{
MemoryStream ms = new MemoryStream();
objSftp.DownloadFile(file.FullName, ms);
using (FileStream fs = new FileStream(strTarget + "\\" + file.Name, FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
fs.Write(bytes, 0, bytes.Length);
ms.Close();
}
}
}
}
objSftp.Disconnect();
}
Any ideas?New Post: Setting transfer mode to binary
ms.Postion = 0;
This fixed the problem.
New Post: Timeout establishing SSH sessions
Can any of you provide a small repro ?
Preferrable one that I can run again a public server, but I'll take whatever I can get :p
New Post: Simple .cshtml example?
@using Renci.SshNet.Common;
@using Renci.SshNet.Channels;
@using Renci.SshNet.Compression;
@using Renci.SshNet.Sftp;
@using Renci.SshNet.Security;
@using Renci.SshNet.Messages;
@{
using (var sshClient = new SshClient("server", "user", "password"))
{
var terminal = sshClient.RunCommand("ls -l");
var output = terminal.Result;
}
}
This spits out the following error on the line "var terminal = sshClient.RunCommand("ls -l");": "Exception Details: System.ArgumentNullException: Value cannot be null." Would someone be able to help me?
New Post: Simple .cshtml example?
@using Renci;
@using Renci.SshNet;
@using Renci.SshNet.NetConf;
@using Renci.SshNet.Common;
@using Renci.SshNet.Channels;
@using Renci.SshNet.Compression;
@using Renci.SshNet.Sftp;
@using Renci.SshNet.Security;
@using Renci.SshNet.Messages;
@{
var RemoteHost = "server";
var RemoteUserName = "user";
var RemotePassWord = "password";
var connectionInfo = new PasswordConnectionInfo(RemoteHost, RemoteUserName, RemotePassWord);
var ssh = new SshClient(connectionInfo);
ssh.Connect();
var terminal = ssh.RunCommand("ls -l");
Response.Write(terminal.Result);
}