Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// 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.
final ftp = CkFtp2();
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';
try {
ftp.connect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
ftp.changeRemoteDir('public_html');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Perform a sync.
final mode = 6;
try {
ftp.syncLocalTree('qa_output/site', mode);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the list of files that were uploaded, downloaded, or deleted by that sync.
final synced = CkStringTable();
ftp.getSyncedFiles(synced);
final n = synced.count;
print('Affected files: $n');
for (var i = 0; i < n; i++) {
final String relPath;
try {
relPath = synced.stringAt(i);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print(relPath);
}
try {
ftp.disconnect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}