This project is read-only.

ssh conversation

Mar 19, 2014 at 9:02 PM
Hi all, I did a deep search about how to make a ssh conversation with this .dll with no luck.

Any of you guys, have a very basic example of how to set a "conversation vis ssh"? Depending of the output at the server, I'll run some commands.

This is for a small project that I'm trying to code. From some windows hosts I want to connect to some unix servers, analyze the ouputs, aunthenticate to the server and finally run some health checks.

Thank you very much.
Mar 25, 2014 at 2:45 AM
Any ideas, please?
I just need a basic example of ssh conversation.

Thanks.
Mar 25, 2014 at 9:16 AM
There are docs you can read and the tests can be used as "example".

e.g.: https://sshnet.codeplex.com/SourceControl/latest#Renci.SshClient/Renci.SshNet.Tests/Classes/SshClientTest.cs
Mar 27, 2014 at 8:55 PM
Thank you. I'll keep searching...
Mar 28, 2014 at 7:27 AM
Why searching? The tests do exactly what you asked for.
Mar 28, 2014 at 2:56 PM
Edited Mar 28, 2014 at 3:04 PM
Griffin90,

In working with Cisco equipment, for example, I found that you had to be careful about when to issue CR, LF, CRLF, or even nothing! To help others extend renci, I wrote a short blog article on how to wrap commands/messages sent.

At first I added the necessary variations to the source (didn't I post that a while ago as a suggestion?), but when new source was coming out without the subtle inclusions, I had to wrap it to do the same thing.

Maybe it will help you...?

All around, best ssh app/library out there, IMHO... :)

pat
:)
Mar 29, 2014 at 12:04 AM
Edited Mar 29, 2014 at 12:06 AM
Hello. First of all, thanks both of you for your time.

This is what I got so far:
    Dim ConnString As New Renci.SshNet.PasswordConnectionInfo("myserver.com", "xx65", "password")
        Dim sshConn As New Renci.SshNet.SshClient(ConnString)
        Dim comm As Renci.SshNet.SshCommand
        
        Using sshConn
            sshConn.Connect()
            
            'Execute command and print the results. 
            comm = sshConn.RunCommand(" tail -50 /var/log/messages | uname -a")
            RichResult.Text = comm.Result
    
    sshConn.Disconnect()
        End Using
I can only send one command and do not know how to interact with the ouputs at server and do not how to get them. As you can notice, I'm pretty new in vb.net. Once I'm connected as a regular user I need to get root priviligies so I can run some health checks at server. Depending on the server, maybe I'll have to renew my password becacuse of the security policies (this is one of the reasons why I need to analyze the ouputs at server side). Once I'm root I'll be able to run the commands.

BogusException, I'm checking the example at your blog. It seems easy to understand, I hope I can get it

Thanks again.
Mar 29, 2014 at 1:41 AM
Edited Mar 29, 2014 at 2:01 AM
Griffin90,

You're on the right track. Just like a real terminal, the results of a command are returned like they would be in a terminal session if you were 'manually' logged on via SSH. When you capture the result (output) from the terminal, it is in a string, and you can parse it either yourself, or via one of the built in regex methods.

You will do well in the long run by going through the help examples, as well as even perusing the source. Build small, short examples to test each one, and expand on them if you need to.

Because there are a lot of C# examples, you can grab the free version of free version of Instant VB from Tangible Solutions to convert. I write in both, but like VB more. Also, others have posted code using Renci, so a clever Google search will turn up quite a few examples as well.

At least you aren't trying all the other libraries, beating your head against the wall for days or weeks, then trying another before finally stopping at Renci... :)

Good hunting!

pat
:)

P.S. You'll find my blog post has complete examples you can just run... The examples hit a Cisco ASA/router, but the 4 SendCommand variations allow you to mix & match for any OS/terminal/device.
Mar 29, 2014 at 2:04 AM
Griffin90,

My email notification of your latest looked like this:
Dim ConnSring As New Renci.SshNet.PasswordConnectionInfo("myserver.com", "xx65", "password")
Dim sshConn As New Renci.SshNet.SshClient(ConnString)
Dim comm As Renci.SshNet.SshCommand
        
Using sshClient
    sshConn.Connect()
            
    'Execute command and print the results. 
    'comm = sshClient.RunCommand("echo "whatever" | tail -50 /var/log/messages | uname -a")

    'RichResult.Text = comm.Result
    sshConn.Disconnect()
End Using
...which has a single quote "'" at the beginning of a few key lines. I hope you know that a line starting with a single quote is considered by the compiler as a comment... :)
Mar 29, 2014 at 2:31 AM
Hello Pat, I know that, I know the basics of visual basic... :)

Those lines were commented because there were other lines on the code that I removed in order to make my point in this thread. Bunch of lines that I wrote in my "testing phase", no luck till now.

I'll keep on trying. have a good weekend.