Sample code for 30+ languages & platforms
Rust

SFTP Create Directory

See more SFTP Examples

Demonstrates how to create a new directory on the remote SFTP server.

Chilkat Rust Downloads

Rust

// 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.

let sftp = chilkat::SFtp::new();

// Set some timeouts, in milliseconds:
sftp.set_connect_timeout_ms(15000);
sftp.set_idle_timeout_ms(15000);

// Connect to the SSH server.  
if sftp.connect("sftp.example.com", 22).is_err() {
    println!("{}", sftp.last_error_text());
    return;
}

// Authenticate with the SSH server.  Chilkat SFTP supports
// both password-based authenication as well as public-key
// authentication.  This example uses password authenication.
if sftp.authenticate_pw("myLogin", "myPassword").is_err() {
    println!("{}", sftp.last_error_text());
    return;
}

// After authenticating, the SFTP subsystem must be initialized:
if sftp.initialize_sftp().is_err() {
    println!("{}", sftp.last_error_text());
    return;
}

// Create a new directory:
if sftp.create_dir("myNewDir").is_err() {
    println!("{}", sftp.last_error_text());
    return;
}

println!("Success.");