Rust
Rust
Restart/Resume FTP Upload
See more FTP Examples
Demonstrates how to restart / resume an FTP upload.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 file will be uploaded.
if ftp.change_remote_dir("temp").is_err() {
println!("{}", ftp.last_error_text());
return;
}
// In this example, assume that a previous FTP upload failed,
// and the incomplete file (bigFile.zip) exists on the FTP server.
// You only need to set the RestartNext property to resume
// the upload. When RestartNext is set, the next call
// to PutFile (or PutFileFromBinaryData, PutFileFromTextData)
// will automatically resume the upload from the point of failure.
// (The way it works is that the FTP component sends a "SIZE";
// command to the FTP server to find out how many bytes of
// the file already exist on the server. It then begins
// uploading from that point.
// Note: After PutFile is called, the RestartNext property
// is automatically set to false.
ftp.set_restart_next(true);
// Upload a file with restart.
let local_filename = "bigFile.zip".to_string();
let remote_filename = "bigFile.zip".to_string();
if ftp.put_file(&local_filename, &remote_filename).is_err() {
println!("{}", ftp.last_error_text());
return;
}
let _ = ftp.disconnect().is_ok();
println!("File Uploaded!");