Sample code for 30+ languages & platforms
Zig

FTPS with Client Cert from Windows Certificate Store

See more FTP Examples

Demonstrates how to do mutual TLS authentication using a client certificate installed in the Windows certificate store.

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");

    // If using implicit TLS, you probably want port 990..
    ftp.setPort(990);

    // Set this to false for implicit TLS, otherwise set to true for explicit TLS (where port is typically 21).
    ftp.setAuthTls(false);

    // Set this to true for implicit TLS, otherwise set to false.
    ftp.setSsl(true);

    const cert = try chilkat.Cert.init();
    defer cert.deinit();
    cert.loadByCommonName("The common name of your certificate") catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    // Use this certificate for our TLS mutually authenticated connection:
    ftp.setSslClientCert(cert) catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    // Establish the TLS connection with the FTP server.
    ftp.connectOnly() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    // If a login is required, then login with the FTP account login/password.
    ftp.setUsername("myLogin");
    ftp.setPassword("myPassword");
    ftp.loginAfterConnectOnly() catch {
        std.debug.print("{s}\n", .{try ftp.getLastErrorText(alloc)});
        return;
    };

    // Do whatever you're doing to do ...
    // upload files, download files, etc...

    // .....
    // .....

    try ftp.disconnect();
}