Zig
Zig
FTP Download File to a Stream
Demonstrates how to FTP download a file to a Chilkat stream.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 the Chilkat FTP2 API to have been previously unlocked.
// See FTP2 Unlock Sample for sample code.
const ftp = try chilkat.Ftp2.init();
defer ftp.deinit();
ftp.setHostname("my-ftp-server.com");
ftp.setPort(21);
ftp.setUsername("mFtpLogin");
ftp.setPassword("myFtpPassword");
ftp.setAuthTls(true);
ftp.setPassive(true);
// Connect and login to the FTP server using TLS.
ftp.connect() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Move to the sub-directory (from the FTP user's home directory) where the file is located.
ftp.changeRemoteDir("temp") catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Stream to this local file:
const stream_obj = try chilkat.Stream.init();
defer stream_obj.deinit();
stream_obj.setSinkFile("c:/temp/qa_output/penguins2.jpg");
ftp.getFileToStream("penguins2.jpg", stream_obj) catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
ftp.disconnect() catch {};
std.debug.print("Success.\n", .{});
}