Contents of Receive Buffer - WeOnlyDo Discussion board

Contents of Receive Buffer (General questions)

by bmclellan, Thursday, August 23, 2007, 15:15 (6302 days ago)

Hello,

Is it possible to see what is being returned to the ssh object when I user the 'waitFor' command?

I am attempting to waitfor a particular string which times out on me, however I would like to see what was returned in the receive buffer to make sure I am at the right part in my prompts.

Thanks!
Barry

Re: Contents of Receive Buffer

by wodDamir, Thursday, August 23, 2007, 15:31 (6302 days ago) @ bmclellan

Hi Berry,

You should try issuing a Receive Call to see what was actually received. I.e if I do the following (VB):
--------------------------------------------
ssh1.HostName = my_hostname
ssh1.Login = my_login
ssh1.Password = my_password
ssh1.Protocol = SSHAuto
ssh1.Blocking = True
ssh1.Connect
On Error Resume Next
Debug.Print ssh1.WaitFor( joe@debian , 10)
Debug.Print ssh1.Receive
--------------------------------------------

I receive everything that arrived, although Timeout occured on my WaitFor Call (I set incorrect prompt on purpose).

Hope I helped.

Regards,
Damba

Re: Contents of Receive Buffer

by bmclellan, Thursday, August 23, 2007, 17:08 (6302 days ago) @ wodDamir

Thanks Damba,

I am using Winbatch to code this (www.winbatch.com) do you have any experience with this language? It is kind of like VB6. If I can get this to work, I will be posting it on their usergroup which will probably generate a lot of traffic for you!

After the waitFor, will it throw an exception, or will it nicely return a '1' if found, or a '0' if not?

Thanks!
Barry

Re: Contents of Receive Buffer

by wodSupport, Thursday, August 23, 2007, 18:34 (6302 days ago) @ bmclellan

Barry,

I believe you can call our error as exception. We infact send receive code, but COM/ActiveX wrapper usually translates it to exception.

Kreso

Re: Contents of Receive Buffer

by wodSupport, Thursday, August 23, 2007, 18:35 (6302 days ago) @ wodSupport

Barry,

is there a chance we can download winbatch (at least a DEMO) and try it out? I would appreciate if you could send your code what you have so far, so we can see how this works, and perhaps we could change it a bit so it works they way it should?

If so, can you give us few pointers on how/where to start?

Kreso

Re: Contents of Receive Buffer

by bmclellan, Thursday, August 23, 2007, 18:52 (6302 days ago) @ wodSupport

Hello,

You can definitely download it and try it out for 30 days or so, go to http://www.winbatch.com/download.html and click on the download link under: Winbatch, or here is a direct link: http://files.winbatch.com/wwwftp/wb01/wb44i07c.zip

They also have a fantastic web board to post questions on: http://webboard.winbatch.com/

Once you download the studio, start it up and save your file with a .wbt extension.

Here is my starting point in the code:

objSSH = ObjectCreate( WeOnlyDo.wodSSHCom.1 )
objSSH.HostName = IP
objSSH.Port = Port
objSSH.Login = UserName
objSSH.Password = Password
objSSH.Blocking = 1
objSSH.Protocol = 4
objSSH.Timeout = 5

t1 = objSSH.Connect
;I was hoping this would return a 1 or 0, and not an exception which get's harder to trap

t1 = objSSH.WaitFor( [513] )
;again, hoping a return code instead of an exception would be sent back to me

;at some point I would need to see what is sitting in the receive buffer if the above doesn't work

objSSH.Disconnect

Thanks again for your help!
Barry

Re: Contents of Receive Buffer

by wodDamir, Thursday, August 23, 2007, 21:02 (6301 days ago) @ bmclellan

Hi Barry,

This is the code I tried in WinBatch:
------------------------------------------------
IntControl(73, 2, 0, 0, 0)
objSSH = ObjectCreate( WeOnlyDo.wodSSHCom.1 )
objSSH.HostName = my_hostname
;objSSH.Port = Port <-- This line has no effect
objSSH.Login = my_login
objSSH.Password = my_password
objSSH.Blocking = 1
objSSH.Protocol = 4
objSSH.Timeout = 20

t1 = objSSH.Connect
On Error GoTo :ReceiveResult
t1 = objSSH.WaitFor( [513] ,2)


:ReceiveResult
t1 = objSSH.Receive
objSSH.Disconnect
:EndReceiveResult

:WBErrorHandler
ErrCode = LastError()
ErrText = IntControl(34, ErrCode, 0 , 0, 0)
IntControl(73, 2, 0, 0, 0)
Return
:EndErrorHandler
------------------------------------------------

The result was that the exception was ignored, and t1 had the wanted result stored.

Also, I noticed in your code that you set Protocol after Port Property which isn't right, since Setting Protocol Property automatically overwrites Port with the default Port for the chosen Protocol. In other words, you should always set Port Property after you set Protocol.

Hope I helped.

Regards,
Damba

Re: Contents of Receive Buffer

by bmclellan, Thursday, August 23, 2007, 21:11 (6301 days ago) @ wodDamir

Thanks!

I never would have caught where to set the port!

Did T1 have any values in it at all? Just wondering how I would know if the waitfor worked?

Barry

Re: Contents of Receive Buffer

by wodDamir, Thursday, August 23, 2007, 21:27 (6301 days ago) @ bmclellan

Barry,

Yes, since WaitFor Timed out, the code proceeded to :ReceiveResult (where pointed by GoTo statement), and Receive Method was called.

The stored result was the standard text that i receive any time I log into the server (a welcome screen etc.)

If you wish, you can modify my ReceiveResult sub to this:
---------------------------
:ReceiveResult
t1 = objSSH.Receive
Message( Received Data ,t1)
objSSH.Disconnect
:EndReceiveResult
---------------------------

It will show a MessageBox with the data received.

Regards,
Damba

Re: Contents of Receive Buffer

by bmclellan, Friday, August 24, 2007, 06:32 (6301 days ago) @ wodDamir

Hello,

I have just sent you a screen shot of what is happening. It is almost like something is killing the receive statement, and if I execute it again, the WaitFor command will work.


Thanks!
Barry

Re: Contents of Receive Buffer

by wodDamir, Friday, August 24, 2007, 07:04 (6301 days ago) @ bmclellan

Hi Barry,

That's occuring since not everything was received in first Receive Call. Can you try calling Receive Method with DataReady Property as it's ByteCound Argument?

Something like:

t1 = objSSH.Receive(objSSH.DataReady)

Another thing you could try doing is trying regex Expressions on WaitFor method.

You can try something like this:

t3 = objSSH.WaitFor( regex:[$ #>[]] , 10)

Regards,
Damba

Re: Contents of Receive Buffer

by bmclellan, Friday, August 24, 2007, 18:22 (6301 days ago) @ wodDamir

Sounds good, I will try that later.

Should I maybe have the ReciveData in a while loop?
8
Also, is using the RegEx pattern better than just having WaitFor wait for a line of text?


Thanks!
Barry

Re: Contents of Receive Buffer

by wodDamir, Friday, August 24, 2007, 18:51 (6301 days ago) @ bmclellan

Barry,

If it works for you, I don't see why not. However, it would be great if you could use Events, so that you could call Receive from inside Received Event.

As for RegEx, It's usefull when you don't know exactly what the prompt will look like. Otherwise you need to set the exact match of the prompt you will get.

Regards,
Damba