Zig
Zig
Append to Existing File on FTP Server
See more FTP Examples
Uploads a file to the FTP server. If the remote file (on the FTP server) does not already exist, it is created. Otherwise the uploaded file is appended to the remote file.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.myftpserver.com");
ftp.setUsername("myUsername");
ftp.setPassword("myPassword");
// 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 local_file_path = "/someDirectory/hamlet.xml";
const remote_filename = "hamlet.xml";
// Upload to the FTP server, creating the file if it does not yet exist
// on the FTP server, or appending to the remote file if it already exists.
ftp.appendFile(local_file_path, remote_filename) catch {
std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
return;
};
ftp.disconnect() catch {};
std.debug.print("Success.\n", .{});
}