Zig
Zig
SFTP Create Directory
See more SFTP Examples
Demonstrates how to create a new directory on the remote SFTP server.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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Important: It is helpful to send the contents of the
// sftp.LastErrorText property when requesting support.
const sftp = try chilkat.SFtp.init();
defer sftp.deinit();
// Set some timeouts, in milliseconds:
sftp.setConnectTimeoutMs(15000);
sftp.setIdleTimeoutMs(15000);
// Connect to the SSH server.
sftp.connect("sftp.example.com", 22) catch {
std.debug.print("{s}\n", .{try sftp.getLastErrorText(alloc)});
return;
};
// Authenticate with the SSH server. Chilkat SFTP supports
// both password-based authenication as well as public-key
// authentication. This example uses password authenication.
sftp.authenticatePw("myLogin", "myPassword") catch {
std.debug.print("{s}\n", .{try sftp.getLastErrorText(alloc)});
return;
};
// After authenticating, the SFTP subsystem must be initialized:
sftp.initializeSftp() catch {
std.debug.print("{s}\n", .{try sftp.getLastErrorText(alloc)});
return;
};
// Create a new directory:
sftp.createDir("myNewDir") catch {
std.debug.print("{s}\n", .{try sftp.getLastErrorText(alloc)});
return;
};
std.debug.print("Success.\n", .{});
}