Sample code for 30+ languages & platforms
Delphi DLL

Get the Files Affected by an FTP Sync

See more FTP Examples

Demonstrates the Chilkat Ftp2.GetSyncedFiles method, which reports the relative paths affected by the most recent synchronization. The only argument is a StringTable that receives the paths (uploaded, downloaded, or deleted).

Background: A sync call reports only overall success, but you usually want to know what actually changed — for logging, for triggering follow-up work on just the new files, or to confirm an incremental sync did the minimal transfer. An empty result is meaningful too: it means everything was already up to date. Call it immediately after the sync, before another operation replaces the recorded list.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
ftp: HCkFtp2;
mode: Integer;
synced: HCkStringTable;
n: Integer;
i: Integer;
relPath: PWideChar;

begin
success := False;

//  Demonstrates the Ftp2.GetSyncedFiles method, which reports the relative paths affected by the
//  most recent synchronization operation.  The only argument is a StringTable that receives the
//  paths.

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;

//  Perform a sync.
mode := 6;
success := CkFtp2_SyncLocalTree(ftp,'qa_output/site',mode);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

//  Get the list of files that were uploaded, downloaded, or deleted by that sync.
synced := CkStringTable_Create();
CkFtp2_GetSyncedFiles(ftp,synced);

n := CkStringTable_getCount(synced);
Memo1.Lines.Add('Affected files: ' + IntToStr(n));

for i := 0 to n - 1 do
  begin
    relPath := CkStringTable__stringAt(synced,i);
    if (CkStringTable_getLastMethodSuccess(synced) = False) then
      begin
        Memo1.Lines.Add(CkStringTable__lastErrorText(synced));
        Exit;
      end;
    Memo1.Lines.Add(relPath);
  end;

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

CkFtp2_Dispose(ftp);
CkStringTable_Dispose(synced);