Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Connect to FTP Through an HTTP Proxy
See more FTP Examples
Demonstrates connecting through an HTTP proxy using HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword, HttpProxyAuthMethod, and HttpProxyDomain.
Background: Many corporate networks force outbound traffic through an HTTP proxy, which reaches the FTP control connection via the
CONNECT method — so the proxy must permit CONNECT to the FTP port. HttpProxyAuthMethod is Basic or NTLM, with HttpProxyDomain supplying the Windows domain for NTLM. This is distinct from a traditional FTP proxy, which speaks FTP itself.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ftp2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
begin
success := False;
ftp := TFtp2.Create;
ftp.Hostname := 'ftp.example.com';
ftp.Username := 'myFtpLogin';
// The HTTP proxy through which the FTP control connection is made. Common ports are 8080 and
// 3128.
ftp.HttpProxyHostname := 'proxy.example.com';
ftp.HttpProxyPort := 8080;
// Proxy authentication, if required. HttpProxyAuthMethod is "Basic" or "NTLM"; HttpProxyDomain
// is the Windows domain used for NTLM.
ftp.HttpProxyUsername := 'myProxyLogin';
ftp.HttpProxyPassword := 'myProxyPassword';
ftp.HttpProxyAuthMethod := 'NTLM';
ftp.HttpProxyDomain := 'CORP';
// 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.
ftp.Password := 'myPassword';
success := ftp.Connect();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
WriteLn('Connected through the HTTP proxy.');
success := ftp.Disconnect();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
ftp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.