Reusing connections for multiple commands (wodSSH / wodSSH.NET)

by jdlogicman @, (5141 days ago)

Is there something in the SSH.NET libraries for performing multiple commands across a single connection? I'm doing so many commands in a short period of time that I'm hitting a connection limit.

locked

Re: Reusing connections for multiple commands

by woddrazen @, (5140 days ago) @ jdlogicman

Hi,


Yes, you can send multiple command in non blocking mode using PromptReceived Event.

Here is example:
http://www.weonlydo.com/code.asp?did=Send-multiple-commands-to-SSH-server-using-asynchr...

if you prefer to use blocking mode, then you can use WaitFor and Execute Method to send multiple command.

Here is blocking sample:
http://www.weonlydo.com/code.asp?did=Send-multiple-commands-to-SSH-server-using-synchro...

Let us know how it goes.


Regards,
Drazen

locked

Re: Reusing connections for multiple commands

by jdlogicman @, (5140 days ago) @ woddrazen

When I try that sample code (adapted), I get an exception calling Connect() that the Prompt field is not set. It's sort of a chicken-and-egg problem, where it's not always possible to know what the prompt will be unless you set it yourself.

_ssh = new WeOnlyDo.Client.SSH();
_ssh.Hostname = _host;
_ssh.Login = _user;
_ssh.Password = _password;
_ssh.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto;
_ssh.TerminalType = tty ;
_ssh.Blocking = true;
_ssh.LicenseKey = xxxxxx ;
_ssh.Connect();

Hi,


Yes, you can send multiple command in non blocking mode using PromptReceived Event.

Here is example:
http://www.weonlydo.com/code.asp?did=Send-multiple-commands-to-SSH-server-using-asynchr...

if you prefer to use blocking mode, then you can use WaitFor and Execute Method to send multiple command.

Here is blocking sample:
http://www.weonlydo.com/code.asp?did=Send-multiple-commands-to-SSH-server-using-synchro...

Let us know how it goes.


Regards,
Drazen

locked

Re: Reusing connections for multiple commands

by wodDamir @, (5140 days ago) @ jdlogicman

Hi,

You need to set Prompt property in that case, since otherwise we can't know when command is done executing. You can however change Prompt property during an active connection.

Also, if prompts are generic you can try using Regex values. I would suggest that you check the wodSSH help page on Prompt property:

http://www.weonlydo.com/SSH/Help/wodSSH-Prompt.html

for ActiveX version or

http://www.weonlydo.com/SSH.NET/Help/WeOnlyDo.Client.SSH.Prompt.html

for the .Net version.

Hope this helps.

Regards,
Damba

locked

Re: Reusing connections for multiple commands

by jdlogicman @, (5140 days ago) @ wodDamir

I'm almost there.

I had to go to non-blocking mode and set the prompt explicitly (to be reliable if someone sends me PS1=xxxx). I also had to turn off echoing commands (stty -echo).

Now, it seems that all of the UNIX newlnes are being translated into CRLF. For example if I cat a multiline text file, I get CRLFs on the receiving end.

Is that a property of the SSH library or is that another terminal setting?

locked

Re: Reusing connections for multiple commands

by wodDamir @, (5140 days ago) @ jdlogicman

Hi,

We don't manipulate the data provided by the server. We provide it back exactly as it was given back to us, so I can only assume that it arrived like that.

Why don't you simply change CRLF->LF or vice-versa if that suits you better?

Regards,
Damba

locked

Re: Reusing connections for multiple commands

by jdlogicman @, (5140 days ago) @ wodDamir

Sometimes I need to know the exact file contents. I can always encode on the UNIX side before transferring the text when I need to.

Thanks for your help!

locked

Re: Reusing connections for multiple commands

by wodDamir @, (5140 days ago) @ jdlogicman

Hi,

I'm just glad if we could help. If you run into any other issues, let us know and we'll check out and try to hekp the best way we can.

Regards,
Damba

locked