What best practices should be followed when attempting to duplicate files on a server using PHP functions like ftp_put?
When attempting to duplicate files on a server using PHP functions like ftp_put, it is important to follow best practices to ensure the process is successful and secure. This includes checking for errors during the file transfer, handling file permissions properly, and verifying the file transfer was completed successfully.
<?php
$local_file = 'local_file.txt';
$remote_file = 'remote_file.txt';
$conn_id = ftp_connect('ftp.example.com');
$login_result = ftp_login($conn_id, 'username', 'password');
if (ftp_put($conn_id, $remote_file, $local_file, FTP_BINARY)) {
echo "File transfer successful";
} else {
echo "File transfer failed";
}
ftp_close($conn_id);
?>