Visual Basic 6.0
Visual Basic 6.0
Connect an SSH Tunnel to the SSH Server
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.Connect method, which establishes the SSH connection that carries the tunnel's traffic. The first argument is the SSH server hostname and the second is the port. It performs the connection, SSH handshake, and host-key negotiation, but does not authenticate the SSH user.
Background: Connecting establishes only the SSH transport — the encrypted channel and host-key exchange. It is the point at which the server's identity becomes known, so it is where a security-conscious client checks
HostKeyFingerprint against a trusted value before handing over credentials. Authentication and BeginAccepting follow; nothing is forwarded until they do.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Demonstrates the SshTunnel.Connect method, which establishes the SSH connection that carries
' tunneled traffic. The 1st argument is the SSH server hostname and the 2nd is the port. This
' performs the connection, SSH handshake, and host-key negotiation, but does not authenticate.
Dim tunnel As New ChilkatSshTunnel
' The tunnel forwards accepted local connections to this destination through the SSH server.
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
' Connect to the SSH server. This performs the TCP/proxy connection and SSH handshake, but
' does not authenticate yet.
Dim sshPort As Long
sshPort = 22
success = tunnel.Connect("ssh.example.com",sshPort)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
' Optionally verify the server's host key before authenticating.
Debug.Print "Host key fingerprint: " & tunnel.HostKeyFingerprint
' 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 = 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