Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
ssh: HCkSsh;
hostname: PWideChar;
port: Integer;
password: PWideChar;
begin
success := 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.
ssh := CkSsh_Create();
// Set the proxy hostname (or IP address) and port before connecting. Typical HTTP proxy ports
// are 3128 and 8080.
CkSsh_putHttpProxyHostname(ssh,'proxy.example.com');
CkSsh_putHttpProxyPort(ssh,3128);
// Important: the HTTP proxy must allow non-HTTP traffic to pass through the CONNECT tunnel,
// otherwise this cannot work.
hostname := 'ssh.example.com';
port := 22;
success := CkSsh_Connect(ssh,hostname,port);
if (success = False) then
begin
Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
Exit;
end;
Memo1.Lines.Add('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.
password := 'mySshPassword';
success := CkSsh_AuthenticatePw(ssh,'mySshLogin',password);
if (success = False) then
begin
Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
Exit;
end;
// ... use the SSH connection normally ...
CkSsh_Disconnect(ssh);
CkSsh_Dispose(ssh);