Zig
Zig
Start SFTP Keyboard-Interactive Authentication
See more SFTP Examples
Demonstrates the Chilkat SFtp.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts, which are answered with ContinueKeyboardAuth.
Background: Keyboard-interactive is the prompt-driven authentication method: rather than assuming a single password, the server sends one or more questions — a password, a one-time code, a security question — and the client answers each. This is how SFTP supports two-factor and other challenge-response schemes. The returned XML tells you exactly what to ask and whether to mask the input.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Demonstrates the SFtp.StartKeyboardAuth method, which begins keyboard-interactive
// authentication. The only argument is the login name. It returns XML describing the server's
// prompts, which are answered with ContinueKeyboardAuth.
const sftp = try chilkat.SFtp.init();
defer sftp.deinit();
// Step 1: Connect the SSH transport. Port 22 is the usual port.
const port = 22;
sftp.connect("sftp.example.com", port) catch {
std.debug.print("{s}\n", .{try sftp.getLastErrorText(alloc)});
return;
};
// Begin keyboard-interactive authentication. The returned XML describes the server's prompts.
const info_request_xml = sftp.startKeyboardAuth(alloc, "mySshLogin") catch {
std.debug.print("{s}\n", .{try sftp.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{info_request_xml});
// Answer the prompt(s) with ContinueKeyboardAuth, then call InitializeSftp.
sftp.disconnect();
}