Zig
Zig
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.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.setHostname("ftp.example.com");
ftp.setUsername("myLogin");
ftp.setPassword("myPassword");
// Use explicit TLS
ftp.setAuthTls(true);
ftp.setPort(21);
// Connect and login to the FTP server.
ftp.connect() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Iterate over .txt files.
ftp.setListPattern("*.txt");
const n = ftp.getDirCount();
std.debug.print("n = {d}\n", .{n});
var i: i32 = 0;
while (i < n) {
std.debug.print("{d}: {s}\n", .{ i, try ftp.getFilename(alloc, i) });
i = i + 1;
}
}