Sample code for 30+ languages & platforms
Rust

FTP Download File to a Stream

Demonstrates how to FTP download a file to a Chilkat stream.

Chilkat Rust Downloads

Rust

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

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

ftp.set_hostname("my-ftp-server.com");
ftp.set_port(21);
ftp.set_username("mFtpLogin");
ftp.set_password("myFtpPassword");
ftp.set_auth_tls(true);
ftp.set_passive(true);

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

// Move to the sub-directory (from the FTP user's home directory) where the file is located.
if ftp.change_remote_dir("temp").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Stream to this local file:
let stream_obj = chilkat::Stream::new();
stream_obj.set_sink_file("c:/temp/qa_output/penguins2.jpg");

if ftp.get_file_to_stream("penguins2.jpg", &stream_obj).is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

let _ = ftp.disconnect();

println!("Success.");