PowerBuilder
PowerBuilder
SSH Through an HTTP Proxy
See more SSH Examples
Demonstrates connecting to an SSH server through an HTTP proxy, using the HTTP/1.1 CONNECT method. Set HttpProxyHostname and HttpProxyPort before calling Connect.
Background:
CONNECT asks the proxy to open a raw TCP tunnel rather than to fetch a page, which is how non-HTTP protocols traverse an HTTP proxy. The important caveat is that the proxy must be configured to permit it: many proxies allow CONNECT only to port 443, in which case an SSH connection on port 22 is refused no matter how the client is configured. Typical proxy ports are 3128 and 8080.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
string ls_Hostname
integer li_Port
string ls_Password
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Demonstrates connecting to an SSH server through an HTTP proxy, using the HTTP/1.1 CONNECT
// method.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
destroy loo_Ssh
MessageBox("Error","Connecting to COM object failed")
return
end if
// Set the proxy hostname (or IP address) and port before connecting. Typical HTTP proxy ports
// are 3128 and 8080.
loo_Ssh.HttpProxyHostname = "proxy.example.com"
loo_Ssh.HttpProxyPort = 3128
// Important: the HTTP proxy must allow non-HTTP traffic to pass through the CONNECT tunnel,
// otherwise this cannot work.
ls_Hostname = "ssh.example.com"
li_Port = 22
li_Success = loo_Ssh.Connect(ls_Hostname,li_Port)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "Connected to the SSH server through the HTTP proxy."
// 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_Ssh.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// ... use the SSH connection normally ...
loo_Ssh.Disconnect()
destroy loo_Ssh