Sample code for 30+ languages & platforms
Delphi DLL

Enable FTP MODE Z Compression

See more FTP Examples

Demonstrates the Chilkat Ftp2.SetModeZ method, which enables MODE Z compression for subsequent data connections. It takes no arguments. Call it after connecting and only when the HasModeZ property is true.

Background: MODE Z compresses data on the fly (using zlib) as it crosses the wire, which can meaningfully speed up transfers of compressible content — text, HTML, logs — over a slow link. It is a server extension, so check HasModeZ first and expect it to be unavailable on many servers. There is little benefit for already-compressed data such as images or archives, where the CPU cost of compression buys almost nothing.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
ftp: HCkFtp2;

begin
success := False;

//  Demonstrates the Ftp2.SetModeZ method, which enables MODE Z compression for subsequent data
//  connections.  It takes no arguments.  Call it after connecting, and only when the HasModeZ
//  property indicates the server supports it.

ftp := CkFtp2_Create();

CkFtp2_putHostname(ftp,'ftp.example.com');
CkFtp2_putUsername(ftp,'myFtpLogin');

//  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.
CkFtp2_putPassword(ftp,'myPassword');

success := CkFtp2_Connect(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

success := CkFtp2_ChangeRemoteDir(ftp,'public_html');
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

//  Only enable compression if the server advertises MODE Z support.
if (CkFtp2_getHasModeZ(ftp)) then
  begin
    success := CkFtp2_SetModeZ(ftp);
    if (success = False) then
      begin
        Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
        Exit;
      end;
    Memo1.Lines.Add('MODE Z compression enabled.');
  end
else
  begin
    Memo1.Lines.Add('The server does not support MODE Z.');
  end;

//  Subsequent uploads, downloads, and listings are transferred compressed.

success := CkFtp2_Disconnect(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

CkFtp2_Dispose(ftp);