Rust
Rust
Save String Variable to File on FTP Server
See more FTP Examples
Save the contents of a string variable to a file on an FTP server.Chilkat Rust Downloads
// 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;
}
// 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;
}
// Upload the contents of a string to a remote file.
let file_contents = "To be, or not to be: that is the question.".to_string();
let remote_filename = "hamletQuote.txt".to_string();
if ftp.put_file_from_text_data(&remote_filename, &file_contents, "utf-8").is_err() {
println!("{}", ftp.last_error_text());
return;
}
let _ = ftp.disconnect().is_ok();
println!("String Uploaded!");