Sample code for 30+ languages & platforms
Zig

Rename Remote File

See more FTP Examples

Rename a remote file or directory. The RenameRemoteFile can be called to rename either a remote file or directory.

Chilkat Zig Downloads

Zig
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("login");
    ftp.setPassword("password");

    // Connect and login to the FTP server.
    ftp.connect() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    // Set the current remote directory to where the file
    // is located:
    ftp.changeRemoteDir("/testing") catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    // Rename the remote file (or directory)
    const existing_filename = "hello.txt";
    const new_filename = "goodbye.txt";
    ftp.renameRemoteFile(existing_filename, new_filename) catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    try ftp.disconnect();
}