DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTunnel
Integer iSshPort
String sPassword
Integer iListenPort
Boolean iWaitForThreadExit
String sTemp1
Move False To iSuccess
// Demonstrates reaching the SSH server through an outbound HTTP proxy using the SshTunnel
// properties HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword,
// HttpProxyAuthMethod, and HttpProxyDomain.
Get Create (RefClass(cComChilkatSshTunnel)) To hoTunnel
If (Not(IsComObjectCreated(hoTunnel))) Begin
Send CreateComObject of hoTunnel
End
// 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.)
Set ComHttpProxyHostname Of hoTunnel To "proxy.example.com"
Set ComHttpProxyPort Of hoTunnel To 8080
// Proxy authentication, if the proxy requires it. Valid HttpProxyAuthMethod values are "Basic"
// and "NTLM". HttpProxyDomain is the optional Windows domain used for NTLM.
Set ComHttpProxyUsername Of hoTunnel To "myProxyLogin"
Set ComHttpProxyPassword Of hoTunnel To "myProxyPassword"
Set ComHttpProxyAuthMethod Of hoTunnel To "NTLM"
Set ComHttpProxyDomain Of hoTunnel To "CORP"
Set ComDestHostname Of hoTunnel To "db.internal.example.com"
Set ComDestPort Of hoTunnel To 5432
Move 22 To iSshPort
Get ComConnect Of hoTunnel "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Move "mySshPassword" To sPassword
Get ComAuthenticatePw Of hoTunnel "mySshLogin" sPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Move 1080 To iListenPort
Get ComBeginAccepting Of hoTunnel iListenPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Tunnel established through the HTTP proxy."
Move True To iWaitForThreadExit
Get ComCloseTunnel Of hoTunnel iWaitForThreadExit To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure