Zig
Zig
Upload Directory Tree
See more FTP Examples
Upload an entire directory tree from the local filesystem to an FTP server.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 requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const ftp = try chilkat.Ftp2.init();
defer ftp.deinit();
ftp.setKeepSessionLog(true);
ftp.setHostname("ftp.example.com");
ftp.setUsername("login");
ftp.setPassword("password");
// Connect and login to the FTP server.
ftp.connect() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Set the current remote directory to the root where the
// directory tree will be uploaded.
ftp.changeRemoteDir("/something") catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Upload the entire directory tree rooted at c:/temp/something
ftp.putTree("c:/temp/something") catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
try ftp.disconnect();
std.debug.print("{s}\n", .{try ftp.getSessionLog(alloc)});
}