Embed a SSH Client in VB.net application

Jul 22, 2011 at 12:04 PM

Hello,

I have a VB.NET Application. I want to Embed a SSh Client in it so that I can run commands and collect logs from a Remote Server which is accessible through a SSH Connection. My requirement is pretty simple. I should be able to connect to the Remote Server through SSH using Username/Password. Run some commands and collect the Logs. Thats it !

Can I do this with SSH.NET ?

If Yes, can I have a sample Code if possible ?

 

Regards//

Rohit Sengupta

Coordinator
Jul 22, 2011 at 1:05 PM

Hi,

 

Yes, its possible.

I am not a VB person I can but here is an example that I found in this forum posted by user user:

Using client As New SshClient("10.10.10.1", 4118, "user", "pass")
            client.Connect()

            Dim cmd As SshCommand
            Dim result As String
            Dim result2 As String

            cmd = client.CreateCommand("who")
            cmd.CommandTimeout = TimeSpan.FromSeconds(10)
            result = cmd.Execute
            result2 = cmd.Error
            RichTextBox1.Text = cmd.ExitStatus

            If String.IsNullOrEmpty(result2) Then
                RichTextBox1.Text = result2
            End If

            RichTextBox1.Text = result

            client.Disconnect()
End Using

Hope it helps.

 

Oleg

Jul 22, 2011 at 1:21 PM

Thanks for your quick response. I will try this out. I think the "RichTextBox1" would be having the Command outputs which I require. I will try this code and get back to you regarding the result !

Regards//

Rohit Sengupta

Jul 22, 2011 at 2:43 PM

I would like to ask what all assemblies(.dll) do I need to add to my project before I can use this code ?

Coordinator
Jul 22, 2011 at 2:57 PM

Only one,

Renci.SshNet.

Jul 26, 2011 at 4:13 PM

Hello,

I cannot make it work :-(

I downloaded this Binary and Addded the Reference to my VB.NET 2008 Project. It shows a mark on the Reference(Dont know why). And also I cannot use any of its Classes. Can you please help. Of all the SSH proucts available, I found this one most suitable for my Project.

Regards//

Rohit Sengupta

Coordinator
Jul 26, 2011 at 4:34 PM

What .NET version do you use in your project?

May be this i s a problem, since my library is compiled to work with .NET 4.0, at least at a moment.

Jul 26, 2011 at 6:20 PM

I think I have .NET 1.1, 3.5 and 4.0 but I dont know which one is used in my Project. Just to test, I started a new Windows Application and added the Reference Renci.SSH.NET.dll. But there is a exclaimation mark on the dll in the Reference Tab Under Project.

Please help me to solve this.

Regards//

Rohit Sengupta

Jul 26, 2011 at 6:20 PM
Edited Jul 26, 2011 at 7:33 PM

I think I have .NET 1.1, 3.5 and 4.0 but I dont know which one is used in my Project. Just to test, I started a new Windows Application and added the Reference Renci.SSH.NET.dll. But there is a exclaimation mark on the dll in the Reference Tab Under Project.

Please help me to solve this.

Maybe I need to add the Reference to GAC ?

Actually its just how to start. So if you can provide me with a .NET Solution file with a simple example(Preferably in VB.NET). My requirement is pretty simple. I need to login to a remote Server through SSH, fire a set of commands and log the output. Is it possible for you to provide me with a sample Solution ? It would be of immense help to me !

Regards//

Rohit Sengupta

Coordinator
Jul 27, 2011 at 6:47 PM

Rohit,

 

Sorry, I am not a VB.NET developer so dont have any examples in VB.NET.

 

If you like you can download latest changeset which includes lateset version and solution file as well and see if it works for you this way, when you reference it as a project in your solution and not as assembly.

 

Thanks,

Oleg