Sample code for 30+ languages & platforms
Rust

Delete a Remote FTP File (DELE)

See more FTP Examples

Demonstrates the Chilkat Ftp2.DeleteRemoteFile method, which deletes a remote file. The only argument is the remote file path, relative to the current directory or absolute.

Background: Deletion is immediate and permanent — FTP has no trash or undo — so a job that removes files should be certain of the path first. Whether it is allowed depends on the account's permissions on the file and its containing directory. Note that a successful delete does not refresh the cached indexed listing.

Chilkat Rust Downloads

Rust

// Demonstrates the Ftp2.DeleteRemoteFile method, which deletes a remote file.  The only argument
// is the remote file path (relative to the current directory or absolute).

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

ftp.set_hostname("ftp.example.com");
ftp.set_username("myFtpLogin");

// Normally you would not hard-code the password in source.  You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ftp.set_password("myPassword");

if ftp.connect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

if ftp.change_remote_dir("public_html").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

if ftp.delete_remote_file("uploads/obsolete.tmp").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

println!("File deleted.");

if ftp.disconnect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}