Zig
Zig
FTP Automatic Post-Connect Commands
See more FTP Examples
Demonstrates the AutoFeat, AutoSyst, AutoOptsUtf8, and AutoXcrc properties, which control commands Chilkat issues automatically around connecting and transferring.
Background: Chilkat normally probes and adapts to a server on its own:
AutoFeat discovers capabilities with FEAT, AutoSyst learns the OS type to parse legacy listings, and AutoOptsUtf8 enables UTF-8 filenames when the server advertises it. These are on by default and rarely worth changing. AutoXcrc is the exception worth enabling deliberately — it verifies each upload with the server's XCRC checksum, catching corruption automatically where supported.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const ftp = try chilkat.Ftp2.init();
defer ftp.deinit();
ftp.setHostname("ftp.example.com");
ftp.setUsername("myFtpLogin");
// These auto-* properties control commands Chilkat sends automatically after connecting. They
// are on/off by default as noted, and are rarely changed.
// AutoFeat (default true): automatically send FEAT to discover server capabilities.
ftp.setAutoFeat(true);
// AutoSyst (default true): automatically send SYST after login to learn the server OS type.
ftp.setAutoSyst(true);
// AutoOptsUtf8 (default true): send OPTS UTF8 ON when the FEAT response advertises UTF8.
ftp.setAutoOptsUtf8(true);
// AutoXcrc (default false): request an XCRC checksum after each upload and treat a mismatch as
// a failure, giving automatic post-upload verification where the server supports XCRC.
ftp.setAutoXcrc(true);
// 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;
};
std.debug.print("Connected with the configured automatic features.\n", .{});
ftp.disconnect() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
}