PowerBuilder
PowerBuilder
SSH Tunnel Through an Outbound HTTP Proxy
See more SSH Tunnel Examples
Demonstrates reaching the SSH server through an outbound HTTP proxy using the HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword, HttpProxyAuthMethod, and HttpProxyDomain properties.
Background: Many corporate networks force outbound traffic through an HTTP proxy, which reaches non-HTTP services such as SSH via the
CONNECT method — so the proxy must be configured to allow CONNECT to the SSH port. HttpProxyAuthMethod is Basic or NTLM, with HttpProxyDomain supplying the Windows domain for NTLM. Note that if SocksVersion is set, the SOCKS proxy takes precedence and these HTTP settings are ignored.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Tunnel
integer li_SshPort
string ls_Password
integer li_ListenPort
integer li_WaitForThreadExit
li_Success = 0
// Demonstrates reaching the SSH server through an outbound HTTP proxy using the SshTunnel
// properties HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword,
// HttpProxyAuthMethod, and HttpProxyDomain.
loo_Tunnel = create oleobject
li_rc = loo_Tunnel.ConnectToNewObject("Chilkat.SshTunnel")
if li_rc < 0 then
destroy loo_Tunnel
MessageBox("Error","Connecting to COM object failed")
return
end if
// The HTTP proxy through which the outbound connection to the SSH server is made. Common HTTP
// proxy ports include 8080 and 3128. (If SocksVersion is 4 or 5, the SOCKS proxy takes
// precedence and these settings are ignored.)
loo_Tunnel.HttpProxyHostname = "proxy.example.com"
loo_Tunnel.HttpProxyPort = 8080
// Proxy authentication, if the proxy requires it. Valid HttpProxyAuthMethod values are "Basic"
// and "NTLM". HttpProxyDomain is the optional Windows domain used for NTLM.
loo_Tunnel.HttpProxyUsername = "myProxyLogin"
loo_Tunnel.HttpProxyPassword = "myProxyPassword"
loo_Tunnel.HttpProxyAuthMethod = "NTLM"
loo_Tunnel.HttpProxyDomain = "CORP"
loo_Tunnel.DestHostname = "db.internal.example.com"
loo_Tunnel.DestPort = 5432
li_SshPort = 22
li_Success = loo_Tunnel.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
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.
ls_Password = "mySshPassword"
li_Success = loo_Tunnel.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
li_ListenPort = 1080
li_Success = loo_Tunnel.BeginAccepting(li_ListenPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
Write-Debug "Tunnel established through the HTTP proxy."
li_WaitForThreadExit = 1
li_Success = loo_Tunnel.CloseTunnel(li_WaitForThreadExit)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
destroy loo_Tunnel