delphi - WeOnlyDo Discussion board

delphi (General questions)

by arno, Friday, January 04, 2008, 18:15 (6168 days ago)

Hello,

I try this code in delphi
wodSSHCom1.Hostname := Edit1.Text;
wodSSHCom1.Login := Edit2.Text;
wodSSHCom1.Password := Edit3.Text;
wodSSHCom1.Protocol := ComboBox1.ItemIndex;

if ComboBox1.ItemIndex = 1 then wodSSHCom1.Port := 23; // for telnet
if ComboBox1.ItemIndex > 1 then wodSSHCom1.Port := 22; // for SSH

memo1.Text := '';
PrintList('Connecting...' + chr(13) + chr(10));


wodSSHCom1.Blocking:=true;
wodSSHCom1.Connect1; // Connect is protected keyword for Delphi,
// so wrapper moved our Connect to Connect1
memo2.Text:=wodSSHCom1.Execute('ls -l'+#10,'regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9~/]+[$ #>] $');

The connect is ok

But after the command execute i have msg
STATECHANGE: Sending data to server (from Connected to server - idle)
STATECHANGE: Connected to server - idle (from Sending data to server)
STATECHANGE: Receiving data from server (from Connected to server - idle)
STATECHANGE: Connected to server - idle (from Receiving data from server)
STATECHANGE: Receiving data from server (from Connected to server - idle)
STATECHANGE: Connected to server - idle (from Receiving data from server)
STATECHANGE: Receiving data from server (from Connected to server - idle)
STATECHANGE: Connected to server - idle (from Receiving data from server)
STATECHANGE: Receiving data from server (from Connected to server - idle)
STATECHANGE: Connected to server - idle (from Receiving data from server)


but the function wodSSHCom1Received is never call

What is the probleme ?

Re: delphi

by woddrazen, Friday, January 04, 2008, 18:34 (6168 days ago) @ arno

Hi Arno,


Please try something like this in Delphi:
[code]
wodSSHCom1.Connect1;

wodSSHCom1.WaitFor ('regex:[$ #>] $');
wodSSHCom1.DataReady := 0;
memo2.Text := wodSSHCom1.Execute( ls -al + vbLf, 'regex:[$ #>] $');[/code]

Before you execute command using Execute Method you should wait for a prompt to done that. That's why I use WaitFor Method in my code.

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

When using Execute Method you don't need to call wodSSH Receive Method. Execute Method should return response from server. In your case in memo2.

Let us know how it goes.


Regards,
Drazen

Re: delphi

by arno, Friday, January 04, 2008, 20:45 (6167 days ago) @ woddrazen

Hi,

I try this but i have always the same problem

wodSSHCom1.Blocking:=true;
wodSSHCom1.Connect1; // Connect is protected keyword for Delphi,
// so wrapper moved our Connect to Connect1
wodSSHCom1.WaitFor ('regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9~/]+[$ #>] $');
wodSSHCom1.DataReady := 0;
memo2.Text := wodSSHCom1.Execute('ls -al' + #10, 'regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9~/]+[$ #>] $');


Regards,
Arno

Hi Arno,


Please try something like this in Delphi:
[code]
wodSSHCom1.Connect1;

wodSSHCom1.WaitFor ('regex:[$ #>] $');
wodSSHCom1.DataReady := 0;
memo2.Text := wodSSHCom1.Execute( ls -al + vbLf, 'regex:[$ #>] $');[/code]

Before you execute command using Execute Method you should wait for a prompt to done that. That's why I use WaitFor Method in my code.

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

When using Execute Method you don't need to call wodSSH Receive Method. Execute Method should return response from server. In your case in memo2.

Let us know how it goes.


Regards,
Drazen

Re: delphi

by woddrazen, Friday, January 04, 2008, 20:48 (6167 days ago) @ arno

Arno,


What is the value of prompt when you connect to your server?

You can use that value in WaitFor and Execute Method.

Also did you try on my way using my values in regex?


Drazen

Re: delphi

by arno, Sunday, January 06, 2008, 14:33 (6166 days ago) @ woddrazen

Arno,


What is the value of prompt when you connect to your server?

You can use that value in WaitFor and Execute Method.

Also did you try on my way using my values in regex?


Drazen

Re: delphi

by arno, Sunday, January 06, 2008, 14:33 (6166 days ago) @ arno

Hello,

I have this when i am connect
ns25266 ~ #

Re: delphi

by wodDamir, Sunday, January 06, 2008, 18:08 (6166 days ago) @ arno

Arno,

When you use Execute method, the Received and PromptReceived events are internally blocked and won't be raised. This is due to fact that those methods take control of buffer, and when they are used, will automatically strip the received string out of it.

If you still wish the Received Event to be triggered, you should try using Send method instead.

Also, in your sample, does memo2.text get filled with the response to your command?

Regards,
Damba