[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Login to device shell


On 4/18/2014 8:50 PM, Mal wrote:
>
> Hello
>
>  
>
> I am wondering if anyone has written a trivial C program to login to
> an ssh service and execute a simple console command, collect the
> output and display from the program prompt.
>
>  
>
> I have tried to follow the tutorial example with no success..
>
>  
>
> Mal
>
>  
>

Yes, that was precisely what led me to libssh.
I had already used libcli  (http://sites.dparrish.com/libcli) to provide
a login "shell" to my application to run diagnostics and look at
internal variables at run-time, etc.
But libcli uses the telnet protocol and that was unacceptable for
security concerns.
Then I found libssh which would alleviate the security problem and just
had to meld the two libraries together.

The only "trick" is to avoid using the cli_loop() method.
You have to re-code the part that collects user input to read from the
ssh_channel and do the echoing back to the remote side.
Once you collect a line of input that way, you can just dump that into
the existing cli_run_command() as is.
And output is just as easy because libcli will let you provide a
callback to intercept all output and you can redirect it to the ssh_channel.
Other than criss-crossing the input and output, the two libraries remain
completely independent.

I cannot share the code directly because it's not mine to share, but
would be glad to provide the general ideas like this.

- Mike


References:
Login to device shellMal <Malz@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org