How can FTP server configurations be optimized to ensure file integrity during uploads?

To ensure file integrity during uploads on an FTP server, you can optimize the server configurations by enabling passive mode, increasing the timeout settings, using secure FTP protocols like SFTP, and implementing file checksum verification.

// Enable passive mode for FTP connection
ftp_pasv($ftp_conn, true);

// Increase timeout settings for FTP connection
ftp_set_option($ftp_conn, FTP_TIMEOUT_SEC, 600);

// Use secure FTP protocol like SFTP
$ftp_conn = ftp_ssl_connect($ftp_server);

// Implement file checksum verification after upload
$checksum_local = md5_file($local_file);
$checksum_remote = md5_file("ftp://$ftp_server/$remote_file");
if($checksum_local == $checksum_remote) {
    echo "File integrity verified.";
} else {
    echo "File integrity check failed.";
}