Sample code for 30+ languages & platforms
Rust

Delete Files Matching Pattern

See more FTP Examples

The DeleteMatching method deletes all files in the current remote directory matching a wildcarded filename.

Chilkat Rust Downloads

Rust

// 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("www.chilkatsoft.com");
ftp.set_username("MyLogin");
ftp.set_password("MyPassword");

// 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 files to be deleted are located.
// for the FTP account.
if ftp.change_remote_dir("junk").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Delete all files with filenames matching "ftp_*.asp"
let num_deleted = ftp.delete_matching("ftp_*.asp");
if num_deleted < 0 {
    println!("{}", ftp.last_error_text());
    return;
}

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

println!("{} Files Deleted!", num_deleted);