Example 1 — Delete a Remote File
Remove one file and print the result. The host and login are placeholders.
<?php
$ftp = ftp_connect("ftp.example.com");
ftp_login($ftp, "demo_user", "demo_pass");
if (ftp_delete($ftp, "old-report.pdf")) {
echo "File deleted.", PHP_EOL;
} else {
echo "Could not delete the file.", PHP_EOL;
}
ftp_close($ftp); How It Works
- We connect and log in first.
- ftp_delete() asks the server to remove old-report. pdf.
- A true result means the file is gone.
- Otherwise the script prints an error message.

