Sample code for 30+ languages & platforms
Perl

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 Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

# 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).

my $ftp = Chilkat2::Ftp2->new;

$ftp->Hostname('ftp.example.com');
$ftp->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->Password('myPassword');

my $success = $ftp->Connect();
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}

$success = $ftp->ChangeRemoteDir('public_html');
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}

$success = $ftp->DeleteRemoteFile('uploads/obsolete.tmp');
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}

print "File deleted.\n";

$success = $ftp->Disconnect();
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}