B4X
B4X
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 B4X Downloads
Dim success As Boolean = False
' 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.
Dim ssh As ChilkatSsh
ssh.Initialize("ssh")
' Set the proxy hostname (or IP address) and port before connecting. Typical HTTP proxy ports
' are 3128 and 8080.
ssh.HttpProxyHostname = "proxy.example.com"
ssh.HttpProxyPort = 3128
' Important: the HTTP proxy must allow non-HTTP traffic to pass through the CONNECT tunnel,
' otherwise this cannot work.
Dim hostname As String = "ssh.example.com"
Dim port As Int = 22
success = ssh.Connect(hostname, port)
If success = False Then
Log(ssh.LastErrorText)
Return
End If
Log("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.
Dim password As String = "mySshPassword"
success = ssh.AuthenticatePw("mySshLogin", password)
If success = False Then
Log(ssh.LastErrorText)
Return
End If
' ... use the SSH connection normally ...
ssh.Disconnect