Sample code for 30+ languages & platforms
Zig

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 Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // 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.

    const ftp = try chilkat.Ftp2.init();
    defer ftp.deinit();

    ftp.setHostname("ftp.example.com");
    ftp.setUsername("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.setPassword("myPassword");

    ftp.connect() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    ftp.changeRemoteDir("public_html") catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    // Perform a sync.
    const mode = 6;
    ftp.syncLocalTree("qa_output/site", mode) catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    // Get the list of files that were uploaded, downloaded, or deleted by that sync.
    const synced = try chilkat.StringTable.init();
    defer synced.deinit();
    ftp.getSyncedFiles(synced);

    const n = synced.getCount();
    std.debug.print("Affected files: {d}\n", .{n});
    var i: i32 = 0;
    i = 0;
    while (i < n) : (i += 1) {
        const rel_path = synced.stringAt(alloc, i) catch {
            std.debug.print("{s}\n", .{try synced.getLastErrorText(alloc)});
            return;
        };

        std.debug.print("{s}\n", .{rel_path});
    }

    ftp.disconnect() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };
}