Sample code for 30+ languages & platforms
Zig

Use Explicit FTP over TLS

See more FTP Examples

Demonstrates how to connect to an FTP server using explicit FTP over TLS.

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.your-ftp-server.com");
    ftp.setUsername("ftpAccountLogin");
    ftp.setPassword("ftpAccountPassword");

    // Indicate that the "AUTH TLS" command should be use to convert the connection to TLS
    // after the initial TCP connection to port 21 is established.
    ftp.setAuthTls(true);

    // Connect and convert the connection to TLS automatically.
    ftp.connectOnly() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    ftp.loginAfterConnectOnly() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("TLS connection established and successfully authenticated.\n", .{});
}