SSH connection over the already established connected SSH server

0 votes
asked Aug 17, 2012 by Harris (150 points)
edited Mar 19, 2013

How to create another SSH connection to another from already created SSH server. I created SSH connection to SSH server A. And now I want to connect to SSH server B from A. Can you share sample VB code for this?

Thanks Harris

1 Answer

+1 vote
answered Aug 17, 2012 by Jan Sotola (17,670 points)
edited Mar 19, 2013

Here is a VB.NET example:

Imports Rebex.Net

Module Module1

Sub Main()

    'connect to SSH server A'
    Dim session As New SshSession()
    session.Connect("serverA", 22)
    session.Authenticate("userA", "passwordA")

    'connect to SSH server B through SSH server A'
    Dim client As New Ssh()
    client.SetSocketFactory(session.ToSocketFactory()) 'set up tunneling through SSH'
    client.Connect("serverB", 2222)
    client.Login("userB", "passwordB")

    'use the client here...'

End Sub

End Module

For compiling it, you have to reference following libraries:

  • Rebex.Common.dll
  • Rebex.Networking.dll
  • Rebex.SshShell.dll
  • Rebex.Terminal.dll

All these libraries are part of the Rebex SSH Shell package.