What are the potential drawbacks of deleting entire directories via FTP?

Deleting entire directories via FTP can lead to accidental loss of important files and data if not done carefully. It is important to double-check the contents of the directory before deleting it to ensure that no critical files are being removed. Additionally, deleting directories with a large number of files can be time-consuming and may put a strain on the server.

<?php
$ftp_server = "ftp.example.com";
$ftp_user = "username";
$ftp_pass = "password";

$dir_path = "/path/to/directory/to/delete";

$ftp_conn = ftp_connect($ftp_server);
$login = ftp_login($ftp_conn, $ftp_user, $ftp_pass);

if ($login) {
    if (ftp_rmdir($ftp_conn, $dir_path)) {
        echo "Directory deleted successfully";
    } else {
        echo "Error deleting directory";
    }
} else {
    echo "Failed to connect to FTP server";
}

ftp_close($ftp_conn);
?>