Xojo Plugin
Xojo Plugin
SSH Tunnel Through an Outbound SOCKS Proxy
See more SSH Tunnel Examples
Demonstrates reaching the SSH server through an outbound SOCKS proxy using the SocksVersion, SocksHostname, SocksPort, SocksUsername, and SocksPassword properties.
Background: This is the reverse direction from dynamic forwarding: here a SOCKS proxy is used to reach the SSH server, for networks where outbound connections must pass through one.
SocksVersion is the switch — 0 means no SOCKS, while 4 or 5 selects the protocol. SOCKS5 supports username/password authentication and remote DNS; SOCKS4 supports only a username.Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Demonstrates reaching the SSH server through an outbound SOCKS proxy using the SshTunnel
// properties SocksVersion, SocksHostname, SocksPort, SocksUsername, and SocksPassword.
Dim tunnel As New Chilkat.SshTunnel
// Set SocksVersion to 4 or 5 to route the outbound connection to the SSH server through a SOCKS
// proxy. A value of 0 (the default) means no SOCKS proxy.
tunnel.SocksVersion = 5
tunnel.SocksHostname = "socks.example.com"
tunnel.SocksPort = 1080
// SOCKS4 supports only a username; SOCKS5 supports username and password.
tunnel.SocksUsername = "myProxyLogin"
tunnel.SocksPassword = "myProxyPassword"
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
// Connect to the SSH server through the SOCKS proxy configured above.
Dim sshPort As Int32
sshPort = 22
success = tunnel.Connect("ssh.example.com",sshPort)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
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 = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
End If
Dim listenPort As Int32
listenPort = 1080
success = tunnel.BeginAccepting(listenPort)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
End If
System.DebugLog("Tunnel established through the SOCKS proxy.")
Dim waitForThreadExit As Boolean
waitForThreadExit = True
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
End If