Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Limit FTP DownloadTree by Modification Date

See more FTP Examples

Demonstrates the Chilkat Ftp2.SetOldestDateStr method, which sets the oldest remote modification time eligible for DownloadTree. The only argument is an RFC 822 date-time string; files older than it are skipped. It is a void method.

Background: This is a date filter for the recursive download: set a cutoff and DownloadTree pulls only files modified on or after it, ignoring everything older. It is ideal for fetching just recent activity — new logs, today's uploads — from a directory that also holds a large archive you do not want to re-download. The RFC 822 string carries a timezone so the cutoff is unambiguous.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;

  //  Demonstrates the Ftp2.SetOldestDateStr method, which sets the oldest remote modification time
  //  eligible for DownloadTree.  The only argument is an RFC 822 date-time string.  It is a void
  //  method.

  ftp := TFtp2.Create;

  ftp.Hostname := 'ftp.example.com';
  ftp.Username := '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.
  ftp.Password := 'myPassword';

  success := ftp.Connect();
  if (success = False) then
    begin
      WriteLn(ftp.LastErrorText);
      Exit;
    end;

  success := ftp.ChangeRemoteDir('public_html');
  if (success = False) then
    begin
      WriteLn(ftp.LastErrorText);
      Exit;
    end;

  //  Only files modified on or after this date will be considered by DownloadTree.  Files older
  //  than this are skipped.
  ftp.SetOldestDateStr('Wed, 01 Jul 2026 00:00:00 -0000');

  //  Download only the recently-modified files in the remote tree.
  success := ftp.DownloadTree('qa_output/recent');
  if (success = False) then
    begin
      WriteLn(ftp.LastErrorText);
      Exit;
    end;
  WriteLn('Downloaded recently modified files.');

  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.