Zig Requires Chilkat v11.0.0+
Zig
FTP Set Remote File Date/Time Equal to Local File's Last-Modified Date/Time
See more FTP Examples
Demonstrates how to set a remote file's date/time to be equal to a local file's date/time.Important: Not all FTP servers support the ability to set a file's date/time.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
const ftp = try chilkat.Ftp2.init();
defer ftp.deinit();
ftp.setHostname("www.authtls-ftps-server.com");
ftp.setUsername("FTP_LOGIN");
ftp.setPassword("FTP_PASSWORD");
ftp.setAuthTls(true);
ftp.setPort(21);
// Connect to the FTP server using explicit TLS (AUTH TLS).
ftp.connectOnly() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Authenticate.
ftp.loginAfterConnectOnly() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// We're going to get the last-mod date/time for the local file
// "qa_data/hamlet.xml", and then set the remote "hamlet.xml" to this date/time.
const fac = try chilkat.FileAccess.init();
defer fac.deinit();
const dt = try chilkat.DateTime.init();
defer dt.deinit();
const last_mod_timestamp = try fac.getFileTimeStr(alloc, "qa_data/hamlet.xml", 0);
dt.setFromTimestamp(last_mod_timestamp) catch {};
ftp.setRemoteFileDt(dt, "hamlet.xml") catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
ftp.disconnect() catch {};
std.debug.print("Success.\n", .{});
}