Zig
Zig
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.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.my-ftp-server.com");
ftp.setUsername("mFtpLogin");
ftp.setPassword("myFtpPassword");
// Connect to the FTP server.
ftp.connectOnly() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Authenticate with the FTP server.
ftp.loginAfterConnectOnly() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
const bd_a = try chilkat.BinData.init();
defer bd_a.deinit();
bd_a.loadFile("qa_data/jpg/penguins.jpg") catch {};
// Upload the contents of bdA to the FTP server.
const remote_filename = "penguins.jpg";
ftp.putFileBd(bd_a, remote_filename) catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Download...
const bd_b = try chilkat.BinData.init();
defer bd_b.deinit();
ftp.getFileBd(remote_filename, bd_b) catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Verify that bdA and bdB have the exact same contents.
std.debug.print("size of bdA: {d}\n", .{bd_a.getNumBytes()});
if (bd_a.contentsEqual(bd_b)) {
std.debug.print("Contents are equal. Success.\n", .{});
} else {
std.debug.print("Contents are NOT equal. Failed.\n", .{});
}
ftp.disconnect() catch {};
}