Sample code for 30+ languages & platforms
Rust

Quote and SendCommand

See more FTP Examples

Demonstrate the Quote and SendCommand methods.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let ftp = chilkat::Ftp2::new();

ftp.set_hostname("ftp.example.com");
ftp.set_username("login");
ftp.set_password("password");

// Connect and login to the FTP server.
if ftp.connect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Tell the FTP object to keep an in-memory session log
// so we can see the commands sent to the server,
// and the responses received back.
ftp.set_keep_session_log(true);

// Change the current remote directory via the Quote method:
if ftp.quote("CWD junk").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Move back up 
// In this case, ChangeRemoteDir sends "CWD .." to the FTP server.
if ftp.change_remote_dir("..").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Do the same via the SendCommand method where the
// raw FTP server response is returned:
let server_response = ftp.send_command("CWD junk").unwrap_or_default();
if !ftp.last_method_success() {
    println!("{}", ftp.last_error_text());
} else {
    println!("{}", server_response);
}

let _ = ftp.disconnect().is_ok();

println!("Session Log:");
println!("{}", ftp.session_log());