Zig
Zig
FTPS with Mutual TLS Authentication (TLS Client Certificate)
See more FTP Examples
Demonstrates how to do mutual TLS authentication (using a client certificate from a .pfx/.p12).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.setPort(21);
// 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.loadPfxFile("qa_data/pfx/example.pfx", "pfx_password") 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();
}