Sample code for 30+ languages & platforms
Rust

FTP Upload with Progress Event Callbacks

See more FTP Examples

FTP upload with progress event callbacks.

Chilkat Rust Downloads

Rust
struct FtpEvents;

impl chilkat::EventHandler for FtpEvents {
    fn percent_done(&mut self, percent_done: i32) -> bool {
        println!("Percent Done: {}", percent_done);
        false   // return true to abort the method in progress
    }

    fn progress_info(&mut self, name: &str, value: &str) {
        println!("{}: {}", name, value);
    }
}

// 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_event_handler(FtpEvents);

ftp.set_hostname("ftp.someFtpServer.com");
ftp.set_username("my_ftp_username");
ftp.set_password("my_ftp_password");

// 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 file will be uploaded.
if ftp.change_remote_dir("junk").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Upload a file.
let local_path = "c:/temp/hamlet.xml".to_string();
let remote_filename = "hamlet.xml".to_string();

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

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

println!("File Uploaded!");