Sample code for 30+ languages & platforms
VB.NET

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 VB.NET Downloads

VB.NET
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 New Chilkat.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 Integer = 22
success = ssh.Connect(hostname,port)
If (success = False) Then
    Debug.WriteLine(ssh.LastErrorText)
    Exit Sub
End If


Debug.WriteLine("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
    Debug.WriteLine(ssh.LastErrorText)
    Exit Sub
End If


'  ... use the SSH connection normally ...

ssh.Disconnect()