Clear wodSSH Buffers - WeOnlyDo Discussion board

Clear wodSSH Buffers (wodSSH / wodSSH.NET)

by bmclellan, Friday, April 18, 2008, 05:06 (5823 days ago)

Hello,

I am receiving the odd instance where I attempt another receive (while in blocking mode) and I receive the data I had just read previously.

Is there some way to clear out the buffers, or something I need to do ensure the buffers are clear in between each .send command I execute?


Thanks!
Barry

Re: Clear wodSSH Buffers

by woddrazen, Friday, April 18, 2008, 08:25 (5823 days ago) @ bmclellan

Hi Barry,


Can you please try using DataReady Property. You should set DataReady Property value to 0

[code]ssh1.DataReady = 0[/code]

More help for DataReady Property you can find here:
http://www.weonlydo.com/SSH/Help/WODSSHLib~wodSSH~DataReady.html

If that doesn't help, can you maybe send us your code snippet so we can isolate your issue?

Let us know how it goes.


Regards,
Drazen

Re: Clear wodSSH Buffers

by bmclellan, Friday, April 18, 2008, 15:48 (5823 days ago) @ woddrazen

Hello,

I tried setting DataReady property to 0, but it didn't seem to work.

[code]
objSSH.HostName = IP
objSSH.Login = UserName
objSSH.Password = Password
objSSH.Blocking = 1
objSSH.Protocol = Protocol ;= 1 or 4
objSSH.Port = Port
objSSH.Timeout = 180
t1 = objSSH.Connect

objSSH.Send( Command to send )


TimeDelay(3) ;Give time for the command to start allowing us to retrieve data

if timeout < 300 then timeout = timeout + 120 ;if the timeout if way to low, set it to a lower value
objSSH.Timeout = timeout ; + 120 ;length of the timeout + 120 seconds

while (timediffsecs(timeymdhms(),TimeStart) < timeout) ; start a loop - loop will end if : get hung up on(loose carrier), or
if objSSH.DataReady then
t1 = objSSH.Receive(objSSH.DataReady)

;Logic to look in T1 to see if the command is complete
; or if there was an error
; I can't block until timeout, I must continually poll the data at each iteration
; and see if a condition exists within the data returned

returndata = StrCat(returndata,t1)

if objSSH.DataReady<1 then ;no data is ready anymore so break out of loop
timedelay(3) ;give it 3 seconds to make sure nothing more to come
if objSSH.DataReady<1 then
break
end if
end if
end if
end while

objSSH.Timeout = 0 ;set it to not timeout for our parsing routines later
Return returndata

:WBErrorHandler
ErrCode = LastError()
ErrText = IntControl(34, ErrCode, 0 , 0, 0)
Return returndata

[/code]

Re: Clear wodSSH Buffers

by woddrazen, Friday, April 18, 2008, 15:57 (5823 days ago) @ bmclellan

Hi Barry,


You should remove sleep api from your code. Also you should wait for a prompt and then send command. I don't see from your code that you are waiting for a prompt?

You can done that using WaitFor and Regular expression

$ #>]

means it will accept any of those chars ($, ,#,>) if they appear at the end of the line. This includes 99.9 of most UNIX command prompts (including root account).

You can then send command using execute Method. Here is example

[code]Set ssh1 = New wodSSHCom

ssh1.HostName = hostname
ssh1.Protocol = SSH2
ssh1.Blocking = True
ssh1.Login = login
ssh1.Password = password
ssh1.Connect

ssh1.WaitFor ( regex:[$ #>] $ )
ssh1.DataReady = 0
Debug.Print ssh1.Execute( Command to send + vbLf, regex:[$ #>] $ )
ssh1.Disconnect[/code]
Let us know how it goes.


Drazen

Re: Clear wodSSH Buffers

by bmclellan, Friday, April 18, 2008, 16:25 (5823 days ago) @ woddrazen

Hello,

Sorry about that, my code snipped cut out too much!

In my flow, I execute a command, wait for it to finish, parse it, then execute another command.

The WaitFor would be an excellent command to use, however there are several different things that could be returned to me. If there was a way to tell the WaitFor command to wait for multiple things, that would be fantastic, but for now I believe it only waits for one thing.
I would need to be able to say:
waitFor( command , Page , Invalid ) etc

The system I am interfacing to isn't a true UNIX system, but an interface that runs on UNIX.


Thanks!
Barry

Re: Clear wodSSH Buffers

by wodDamir, Friday, April 18, 2008, 16:45 (5823 days ago) @ bmclellan

Barry,

What command are you executing? Can we duplicate this?

Did yu try regex expressions, perhaps regex:[word1|word2|word3] would work?

Regards,
Damba

Re: Clear wodSSH Buffers

by bmclellan, Tuesday, April 29, 2008, 15:37 (5812 days ago) @ wodDamir

Thanks Damba,

Sorry for the late reply, it turned out to be a platform issue where it was sending a duplicate response of data for certain commands!

Everything is working as it should!
Barry