Sample code for 30+ languages & platforms
Rust

Using the FTP Session Log

See more FTP Examples

The Chilkat FTP component can keep a session log if the KeepSessionLog property is turned on. This is helpful in debugging problems. Chilkat support will usually ask for a session log when working to resolve your problem, because it contains a log of the exact commands sent to the FTP server, and the exact responses received.

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");

// Set the KeepSessionLog property in order to keep a session log.
// The session log will continuously grow in memory.  The
// ClearSessionLog method may be called to clear it.  The session
// logging may be turned on/off at any point.
ftp.set_keep_session_log(true);

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

// Change to the remote directory where the existing file is located.
if ftp.change_remote_dir("junk").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// To clear the SessionLog at any point, call ClearSessionLog:
// call ftp.ClearSessionLog();

// Append moreHamlet.txt to hamlet.txt on the FTP server.
let local_filename = "moreHamlet.txt".to_string();
let remote_filename = "hamlet.txt".to_string();

if ftp.append_file(&local_filename, &remote_filename).is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

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

// Display the entire session log:
println!("{}", ftp.session_log());

println!("File Appended!");