EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Blocking SSH call?

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#1126
Posted: 08/31/2006 13:38:13
by Eugene Mayevski (EldoS Corp.)

I've asked the developers to create a sample for you. We'll be back in 2 days.


Sincerely yours
Eugene Mayevski
#1132
Posted: 09/01/2006 03:36:10
by Eugene Mayevski (EldoS Corp.)

Here's the sample you needed.


[ Download ]

Sincerely yours
Eugene Mayevski
#2320
Posted: 02/16/2007 10:46:31
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Hi

I want todo the exact same thing (send a command and wait for an answer) using sendText and receiveText with TElSimpleSSHClient but I want the command to timeout after a period of time. By reading help file, I setup the UseInternalSocket to true and put a SocketTimeout value (ex:15000). My problem is that if I put a timeout value, receiveText is waiting for the complete timeout time, even if the data already came in. If I don't put a timeout value, receiveText takes about 1.5 secs but exactly 15 seconds with that value. How can I acheive that ?
#2321
Posted: 02/16/2007 11:03:35
by Eugene Mayevski (EldoS Corp.)

Use ReceiveData and convert the data into text.


Sincerely yours
Eugene Mayevski
#2322
Posted: 02/16/2007 11:04:35
by Eugene Mayevski (EldoS Corp.)

And please don't misuse private mail. Sending it with asking to look at the forum won't do any good other than annoy people.


Sincerely yours
Eugene Mayevski
#2323
Posted: 02/16/2007 13:05:40
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Thanks for your quick reply and sorry for the private mail, I'm not really used to forums ...

I still have some problems. Here's what I want to acheive : I try to send a set of commands of get the result of it. I'm look for something like php ssh2_exec command (syntax : $Result = ssh2_exec(Connection,command)). If I use ReceiveText, it work but like I previously said, the command wait for all timeout time to happen before getting my answer. With receiveData, the only thing I get is the echo of my command and even if I call receiveData again, I always get empty buffer. I put a code snippet bellow.

Thanks.


Dim ssh as new TElSimpleSSHClient
[...]
ssh.SocketTimeout = 5000
ssh.open
'get connection banner. It works
receive()
[...]
'send a command
Text = ACommand
Dim buffer(text.Length - 1) As Byte
buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(text)
ssh.SendData(buffer, buffer.Length)
'get command result. Doesn't work, I just get echo for
'my command
result = receive()
----------------------------------------------------
Private Function receive() As String
Const BUFFER_LENGTH As Integer = 8192
Dim sb As New System.Text.StringBuilder
Dim size As Integer
Do
Dim buffer(BUFFER_LENGTH - 1) As Byte
Dim errorBuffer(BUFFER_LENGTH - 1) As Byte
size = BUFFER_LENGTH
Dim errorSize As Integer = BUFFER_LENGTH
ssh.ReceiveData(buffer, size, errorBuffer, errorSize)
If size > 0 Then
sb.Append(System.Text.ASCIIEncoding.ASCII.GetString(buffer).Substring(0, size))
End If
Loop Until size < BUFFER_LENGTH
Return sb.ToString
End Function
#2324
Posted: 02/16/2007 13:23:24
by Eugene Mayevski (EldoS Corp.)

JFI: we receive notification when the post in the forum is made.

About the problem:

The code looks almost correct. But ReceiveData doesn't block, so, maybe there's no data when you attempt to read it, just because the data is not yet ready? Maybe you need to read the data until something happens, i.e. until you know that the data is over?

If you just need to execute a command, use Command or Commands properties of ElSimpleSSHClient. This way you know when the data is over -- the connection is closed.


Sincerely yours
Eugene Mayevski
#2330
Posted: 02/19/2007 08:03:45
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Thanks for your answers

If I use the command property, can I get the result of the command somewhere (ex: if my command is "ls", how get I get the result) ?

If I use the command property, what about the timeout ? If I send a command and I didn't get an answer, is the command will fail at some point or the EISimpleSSHClient will wait forever ?

Thanks.
#2331
Posted: 02/19/2007 09:03:21
by Eugene Mayevski (EldoS Corp.)

Quote
Martin Berube wrote:
If I use the command property, can I get the result of the command somewhere (ex: if my command is "ls", how get I get the result) ?


If you mean stdout (i.e. the data sent by the shell in response to ls), then you use ReceiveData to retrieve the command's result. Please check the knowledgebase on the site for detailed explanation.

Quote
Martin Berube wrote:
If I use the command property, what about the timeout ? If I send a command and I didn't get an answer, is the command will fail at some point or the EISimpleSSHClient will wait forever ?


ReceiveData will attempt to read the requested amount of data. If there's no data available then ReceiveData will wait until the data is received from the socket. Waiting will happen until timeout occurs.

To avoid waiting, you can set SocketTimeout to 0. We will add an extra parameter named ReadAll to control waiting for all or any available data.


Sincerely yours
Eugene Mayevski
#2332
Posted: 02/19/2007 09:04:25
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Hi

Maybe I should clearly explain what I want to do and ask you for the best way to acheive this with your components. What I want is :
- Open as connection
- Send a command (calling an inhouse program) and wait for the result of the command (with a timeout management)
- Depending of the result of the command, use sftp (on the same connection if possible) to get a file produced by the inhouse program.
- Close the connection.

That's it. So according to you, what's the best and most simple way to do this, keeping in mind that we have to execute this on many hosts so it should be as quick as possible and that all these operations must be able to timeout if it takes too long.

Thanks again
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 24265 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!