Missing wait for response in SSH.net buffer and mi (General questions)
Hi,
I have the following code:
ssh1.Hostname = 10.248.6.254
ssh1.Protocol = SSH.SupportedProtocols.Telnet
ssh1.Blocking = True
ssh1.Protocol = 1 'Telnet
ssh1.Port = 23 ' first Protocol then Port Property
ssh1.Timeout = 120
ssh1.StripANSI = True
Try
ssh1.Connect()
a = ssh1.WaitFor( Password: , 10)
TextBox1.Text = TextBox1.Text & a
ssh1.Send( cisco + vbLf)
a = ssh1.WaitFor( regex:[$ #>]$ , 10)
TextBox1.Text = TextBox1.Text & a
ssh1.Send( sho env + vbLf)
a = ssh1.WaitFor( regex:[$ #>]$ , 10)
TextBox1.Text = TextBox1.Text & a
ssh1.Send( sho int desc + vbLf)
a = ssh1.WaitFor( regex:[$ #>]$ , 10)
TextBox1.Text = TextBox1.Text & a
MsgBox( done )
Catch ex As Exception
MsgBox( Exception & ex.Message)
End Try
What is happening is that the a seems to miss what i am waiting for. Let me explain, in the output i get back into a the character i am waiting for is not appended to variable a
Also
I have 3 commands one after each other, if i just run this app then all i get back is the first bit of text and not the results of the sho env or sho int desc .
If i put a debug line in and step through it then i get the results, as though it is moving on before i get the results as the last character is in the buffer.
If you hanve any suggerstions that would be great. The ending app will be codeded in asp.net (VB) but to make life easier i am testing this in vb.net, Hopefully we can sort this out as i am keen to purchase this control if we can get it fixed as i am running on the trial version i guess have 22 days remaining.
Thanks
Simon [code][/code]
Re: Missing wait for response in SSH.net buffer an
Hi Simon,
The missing Wait string is normal. But since you know what you're expecting, you can simply append the returned text to your wait string.
As for the issue with not receiving the whole response, do you perhaps receive an exception?
What if you use the exact string instead of regex as wait pattern?
Regards,
Damba
Re: Missing wait for response in SSH.net buffer an
Here is the output from the program above when insurting debug lines
As you can see the > are in there when they are stripped from the wait for. Then my thinking is that it is still in the buffer so when the next waitfor is called it is then trapping that one. Does that make sense?
This is the windrtrtest Router.
No unauthorised access is permitted.
The equipment now being accessed and information available through
this equipment is confidential and proprietary, and may be accessed
or used only as specifically authorized. All other access or use
is prohibited and is subject to legal action.
User Access Verification
windrtrtest>sho env
Main Power Supply is AC
Fan 1 OK
Fan 2 OK
Fan 3 OK
System Temperature: 25 Celsius (normal)
Environmental information last updated 00:00:06 ago
windrtrtest>sho int desc
Interface Status Protocol Description
Gi0/0 up up
Gi0/1 admin down down
BR0/0/0 up down
BR0/0/0:1 down down
BR0/0/0:2 down down
BR0/0/1 up down
BR0/0/1:1 down down
BR0/0/1:2 down down
BR0/1/0 up down
BR0/1/0:1 down down
BR0/1/0:2 down down
BR0/1/1 up down
BR0/1/1:1 down down
BR0/1/1:2 down down
In1/0 up up
windrtrtest
Re: Missing wait for response in SSH.net buffer an
Simon,
Yes, that's a possibility. That's why I asked that you try with exact prompt patterns in WaitFor.
This could be the issue, since in regex statement you wait for > which if not stripped is left in buffer.
You could also set DataReady property to 0 after each WaitFor, to make sure buffer is cleared.
Can you please try that?
Regards,
Damba
Re: Missing wait for response in SSH.net buffer an
Hello,
I am experiencing a similar error. I don't know the exact pattern in my case. I tried using DataReady (below code) but I still am not getting the entire response. However if I run the code in debug mode I see that the DataReady piece is being hit and I am getting the entire response back.
while (Ssh1.DataReady > 0)
{
//Get data from buffer.
SaveLogMessage( Attempting to get Additional data from buffer );
response += Ssh1.Receive();
}
Thanks,
Sunny
Simon,
Yes, that's a possibility. That's why I asked that you try with exact prompt patterns in WaitFor.
This could be the issue, since in regex statement you wait for > which if not stripped is left in buffer.
You could also set DataReady property to 0 after each WaitFor, to make sure buffer is cleared.
Can you please try that?
Regards,
Damba
Re: Missing wait for response in SSH.net buffer an
Hi Sunny,
You can use regular expressions in WaitFor and Execute Method if you don't know exact prompt.
Something like this[code] ssh1.Blocking = true;
ssh1.Connect();
ssh1.WaitFor( regex:[\$ #>] $ );
ssh1.DataReady = 0;
Console.Write (ssh1.Execute( ls -al\n , regex:[\$ #>] $ ));[/code]
Can you try that and let us know how it goes.
Regards,
Drazen
Re: Missing wait for response in SSH.net buffer an
I know the prompt its > . I am usign the execute method and I am not getting the entire response back.
response = Ssh1.Execute(cmd+
, > , 10);
thanks,
Sunny
Hi Sunny,
You can use regular expressions in WaitFor and Execute Method if you don't know exact prompt.Something like this[code] ssh1.Blocking = true;
ssh1.Connect();ssh1.WaitFor( regex:[\$ #>] $ );
ssh1.DataReady = 0;
Console.Write (ssh1.Execute( ls -al\n , regex:[\$ #>] $ ));[/code]
Can you try that and let us know how it goes.
Regards,
Drazen
Re: Missing wait for response in SSH.net buffer an
Sunny,
Maybe there is some > in the middle of response.
Can you please try using regex? What happened?
Drazen
Re: Missing wait for response in SSH.net buffer an
Ok, I have managed to get this to work with this code below. A suggestion to the developers, that if you are setting the wait for as in a = ssh1.WaitFor( regex:[$ #>]$ , 10) then set the variable a to include the waitfor character as this is actually received in the buffer, This then will save us having to put the catch
If ssh1.DataReady > 0 Then
a = ssh1.Receive
ssh1.DataReady = 0
End If
What are peoples thoughts on this? I am now progressing. Thanks for the help.
MODIFIED CODE:
Try
ssh1.Connect()
a = ssh1.WaitFor( Password: , 10)
TextBox1.Text = TextBox1.Text & a
ssh1.Send( cisco + vbLf)
a = ssh1.WaitFor( regex:[$ #>]$ , 10)
TextBox1.Text = TextBox1.Text & a
If ssh1.DataReady > 0 Then
a = ssh1.Receive
TextBox1.Text = TextBox1.Text & a
ssh1.DataReady = 0
End If
ssh1.Send( sho env + vbLf)
a = ssh1.WaitFor( regex:[$ #>]$ , 10)
TextBox1.Text = TextBox1.Text & a
If ssh1.DataReady > 0 Then
a = ssh1.Receive
TextBox1.Text = TextBox1.Text & a
ssh1.DataReady = 0
End If
ssh1.Send( sho int desc + vbLf)
a = ssh1.WaitFor( regex:[$ #>]$ , 10)
TextBox1.Text = TextBox1.Text & a
If ssh1.DataReady > 0 Then
a = ssh1.Receive
TextBox1.Text = TextBox1.Text & a
ssh1.DataReady = 0
End If
MsgBox( done )
Catch ex As Exception
MsgBox( Exception & ex.Message)
End Try