Visual Basic 6.0
Visual Basic 6.0
Start an SSH Tunnel Listener (BeginAccepting)
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.BeginAccepting method, which creates and starts the local listener on the given port. The only argument is the listen port. Connect and authenticate first — clients accepted before authentication cannot be forwarded. The IsAccepting property reports whether the listener is running.
Background: This is the step that actually turns the object into a working tunnel: it spawns a background thread that accepts local TCP connections and forwards each through the authenticated SSH transport. Because the forwarding runs on its own thread, control returns to your program immediately and the tunnel operates while the rest of the application does other work — which is why a separate
CloseTunnel is needed to shut it down cleanly.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Demonstrates the SshTunnel.BeginAccepting method, which creates and starts the local listener
' on the given port. The only argument is the listen port. Connect and authenticate first;
' clients accepted before authentication cannot be forwarded.
Dim tunnel As New ChilkatSshTunnel
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
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
' 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
' Start the local listener. Local TCP connections to this port are forwarded to DestHostname:DestPort
' through the SSH server.
Dim listenPort As Long
listenPort = 1080
success = tunnel.BeginAccepting(listenPort)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
' IsAccepting reports whether the listener thread is running.
If (tunnel.IsAccepting) Then
Debug.Print "The tunnel is accepting connections on port " & listenPort
End If
' ... the tunnel forwards traffic on a background thread while your application runs ...
Dim waitForThreadExit As Long
waitForThreadExit = 1
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If