What are the best practices for transferring PHP files to a web server to avoid unexpected changes in the code?

When transferring PHP files to a web server, it's important to ensure that the files are uploaded in the correct mode (ASCII or binary) to avoid unexpected changes in the code. To prevent any issues, it's recommended to use a secure file transfer protocol like SFTP or FTPS. Additionally, verifying the file permissions on the server after the transfer can help ensure that the files are not inadvertently modified.

// Sample PHP code snippet for transferring files to a web server using SFTP
$connection = ssh2_connect('example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

$sftp = ssh2_sftp($connection);
$local_file = '/path/to/local/file.php';
$remote_file = 'remote/file.php';

if (ssh2_scp_send($connection, $local_file, $remote_file, 0644)) {
    echo "File transferred successfully!";
} else {
    echo "Error transferring file.";
}