SshClient error while execute command

Mar 2, 2012 at 9:01 AM

Hi,

Sometimes I got exception message while executing command on SshClient: "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."

Frst I create command sshclient.CreateCommand, and execuite it with sshclient.Execute...
exception occurs... "Offset and length were......"
Immidiatly after that if I try again to execute another command I got:

"Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out
   at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle)
   at Renci.SshNet.Channels.ChannelSession.Open()
   at Renci.SshNet.SshCommand.BeginExecute(AsyncCallback callback, Object state)
   at Renci.SshNet.SshCommand.Execute()"

Before exception I've successfully download file using SftpClient

 

Here is the code I'm using:

Using client As New SshClient(RemoteHost, PortSSH, UserName, New PrivateKeyFile(IO.File.OpenRead(Globals.PrivateKeyFile), String.Empty))
client.Connect()

 Dim ftransfer As New SftpClient(RemoteHost, PortFTP, UserName, New PrivateKeyFile(IO.File.OpenRead(Globals.PrivateKeyFile), String.Empty))
     Try
 ftransfer.Connect()
           ' Download file
 Catch ex As Exception
 Finally
         If ftransfer.IsConnected Then
              ftransfer.Disconnect()
         End If
  End Try

Dim cmd As SshCommand
cmd = client.CreateCommand(".......")
Try
  cmd.Execute()
Catch ex As Exception
  !!!!!! First Exception: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
  cmd = client.CreateCommand(".......")
  cmd.Execute()
  !!!!!! After execute second exception occurs: Session operation has timed out...
End Try

If client.IsConnected Then
 client.Disconnect()
 client.Dispose()
End If
End Using

Can sambody tell me what could cause first exception??? Maybe some properties or methods are missing?

Thanks in advance
Vasil 

 

Coordinator
Mar 13, 2012 at 1:28 PM

Hi,

Do you use the same client for both, SFTP and command execution?

If so did yo make some code modification for that?

Also, what command do you execute?

What server you connecting to?

 

Thanks,

Oleg

Mar 15, 2012 at 4:19 PM

Hi,

I am facing same issue

SftpClient sshClient = new SftpClient(strUrl, PortNum, strUid, strPwd);
sshClient.Connect();
sshClient.OperationTimeout = new TimeSpan(0, 4, 0);
sshClient.DownloadFile(LatestFile.FullName, fsDestFile);
if (sshClient.IsConnected) sshClient.Disconnect();
                    fsDestFile.Close(); 



this code is working fine from my local maching it connect to sftp location. but when i upload the code on server its not working it gives the above error stacktrace

can you help to resolve?

Thank you

Coordinator
Mar 15, 2012 at 8:33 PM

Hi,

 

Can you post the exact error and lines of code?

 

This problem would be hard for me to find, unfortunately, since I cannot reproduce it :(

 

Thanks,

Oleg

Mar 22, 2012 at 8:02 AM

Here is exact exception:

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.    
at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle)    
at Renci.SshNet.Channels.Channel.WaitHandle(WaitHandle waitHandle)    
at Renci.SshNet.Channels.ChannelSession.Open()    
at Renci.SshNet.SshCommand.BeginExecute(AsyncCallback callback, Object state)    
at Renci.SshNet.SshCommand.Execute()    
at ... my procedure....

 

Coordinator
Mar 23, 2012 at 1:08 PM

Hmm,

 

I guess I still cant understand where the error might occur or what can cause it.

Can you recreate this problem every time or it happens occasionally?

If you can recreate, does it happen with the same server or file or it behaves the same for different server and files?

 

Sorry for more questions but since I can't recreate this problem I will need to ask you some questions.

Thanks,

Oleg

Mar 27, 2012 at 8:38 AM
Hi olegkap,
thanks, but now the problem is resolved.
its working fine. It was problem from server. their server was not reponding at that time
thanks


On Fri, Mar 23, 2012 at 6:38 PM, olegkap <notifications@codeplex.com> wrote:

From: olegkap

Hmm,

I guess I still cant understand where the error might occur or what can cause it.

Can you recreate this problem every time or it happens occasionally?

If you can recreate, does it happen with the same server or file or it behaves the same for different server and files?

Sorry for more questions but since I can't recreate this problem I will need to ask you some questions.

Thanks,

Oleg

Read the full discussion online.

To add a post to this discussion, reply to this email (sshnet@discussions.codeplex.com)

To start a new discussion for this project, email sshnet@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
Jitendra Maheta
Sr.Software Engineer
Ahmedabad