Are there any potential pitfalls to be aware of when using the ftp_rename() function in PHP?

One potential pitfall when using the ftp_rename() function in PHP is that it may not handle errors gracefully, such as if the source file does not exist or if there are permission issues. To address this, it is recommended to check for errors after calling ftp_rename() and handle them accordingly to prevent unexpected behavior or crashes.

// Rename a file on a remote FTP server
$ftp_server = "ftp.example.com";
$ftp_user = "username";
$ftp_pass = "password";
$source_file = "/path/to/source/file.txt";
$destination_file = "/path/to/destination/file.txt";

// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

// Rename file
if (ftp_rename($conn_id, $source_file, $destination_file)) {
    echo "File renamed successfully";
} else {
    echo "Error renaming file: " . ftp_last_error($conn_id);
}

// Close FTP connection
ftp_close($conn_id);