Zig
Zig
Upload Multiple Files Matching Pattern
See more FTP Examples
The MPutFiles method can be called to upload all files matching a wildcarded filename pattern from a local filesystem 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("my_login");
ftp.setPassword("my_password");
// Connect and login to the FTP server.
ftp.connect() catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Change to the remote directory where the files will be uploaded.
// for the FTP account.
ftp.changeRemoteDir("junk") catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
// Upload all files with filenames matching "c:/temp/ftp_*.asp"
const num_files_uploaded = ftp.mPutFiles("c:/temp/ftp_*.asp");
if (num_files_uploaded < 0) {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
}
try ftp.disconnect();
std.debug.print("{d} Files Uploaded!\n", .{num_files_uploaded});
}