EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Simple Function of SSHclient help

Posted: 08/20/2009 06:13:49
by johnny  (Standard support level)
Joined: 08/20/2009
Posts: 19

What I want to do is to use SimpleSSHClient or SSHClient if no choice to connect to Linux server, send a command once connected (eg: "atrm 48"), and get all the stdout of this command and store in a string. After that send some other commands etc.

I have tried below code but it's not working as the stdout is not the output of the command. Any ideas?

Public Shared received As String
Public Shared recvBuffer(65536) As Byte
Public Shared recvbufferLen As Integer
Public Shared recverr(65536) As Byte
Public Shared recvLen As Integer
client.SendText("atq" + vbCr)
If (Not client.Active) Or (client.Active And client.CanReceive(0)) Then
recvbufferLen = recvBuffer.Length ' 65536
recvLen = recverr.Length ' 65536
client.ReceiveData(recvBuffer, recvbufferLen, recverr, recvLen)
recvbufferLen = recvBuffer.Length
If recvbufferLen > 0 Then
received = received + System.Text.Encoding.ASCII.GetString(recvBuffer, 0, recvbufferLen)
End If
messagebox.show(received) ' stdout from linux
End If
Posted: 08/20/2009 14:21:48
by Eugene Mayevski (Team)

Please check the sample applications that come with SecureBlackbox. Your code is not correct.

Sincerely yours
Eugene Mayevski
Posted: 08/20/2009 21:13:50
by johnny  (Standard support level)
Joined: 08/20/2009
Posts: 19

Well above code are copied fr om one of your forum supporter's code and could you explain a bit more where the problems are?

in any case the above code works well once I inserted a delay after sending command:
Posted: 08/21/2009 00:27:05
by Eugene Mayevski (Team)

Where did you copy the code from? It will work but sometimes it will lose some of the incoming data. Please check the samples.

Sincerely yours
Eugene Mayevski
Posted: 08/23/2009 05:25:00
by johnny  (Standard support level)
Joined: 08/20/2009
Posts: 19

Hi, Eugene,

I followed the sample from below link:

I understand the sample provided use a Timer tick to receive data but it's not suitable for my application.

I am going to use SimpleSSH client as a method to call to send some commands to the linux server. Sometimes I need to receive the output while sometimes I don't.

Any ideas or any good samples for me?
Posted: 08/23/2009 05:52:09
by Eugene Mayevski (Team)

The message you are referring to includes code samples which have a loop (please read until the end of the messages). The construction of this loop must not be changed because any change would break the logic.

The reason is that SSH is asynchronous protocol and the data might come at any moment of time. So you need to poll the socket periodically and retrieve the incoming data from there.

Now, there are sample applications in <SecureBlackbox>\Samples folder. They illustrate the use of the shell channel. Please use them as a guide. Timer is used their to provide user-interactive operations. If you have a script, then you just send the command and then read the incoming data until you receive the reply completely or connection is closed.

Sincerely yours
Eugene Mayevski



Topic viewed 1443 times

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


Back to top

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

Got it!