Visual Basic 6.0
Visual Basic 6.0
Connect an SSH Tunnel Through a Jump Host
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.ConnectThroughSsh method, which connects to an SSH server through an already connected and authenticated Ssh object. The first argument is the jump-host Ssh object, and the second and third are the destination SSH hostname and port.
Background: This chains the tunnel through a "jump host" (bastion): the application reaches a gateway server, then tunnels onward to an SSH server that is only accessible from inside the network. Each hop authenticates separately with its own credentials. The result is a normal
SshTunnel — still requiring its own authentication and BeginAccepting — whose transport is routed through the first connection.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Demonstrates the SshTunnel.ConnectThroughSsh method, which connects to an SSH server through
' an already connected and authenticated Ssh object (a jump host). The 1st argument is the Ssh
' object, and the 2nd and 3rd are the destination SSH hostname and port.
Dim sshJump As New ChilkatSsh
' Connect and authenticate to the jump host first.
Dim sshPort As Long
sshPort = 22
success = sshJump.Connect("jump.example.com",sshPort)
If (success = 0) Then
Debug.Print sshJump.LastErrorText
Exit Sub
End If
' Normally you would not hard-code the password in source. You should instead obtain it
' from an interactive prompt, environment variable, or a secrets vault.
Dim password As String
password = "mySshPassword"
success = sshJump.AuthenticatePw("myJumpLogin",password)
If (success = 0) Then
Debug.Print sshJump.LastErrorText
Exit Sub
End If
' Set up the tunnel and connect to the target SSH server through the jump host.
Dim tunnel As New ChilkatSshTunnel
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
success = tunnel.ConnectThroughSsh(sshJump,"ssh.internal.example.com",sshPort)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
' Authenticate to the target SSH server (its own credentials).
success = tunnel.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
' After authenticating, call BeginAccepting to start listening for local connections to forward.
Dim waitForThreadExit As Long
waitForThreadExit = 1
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
sshJump.Disconnect