How can FTP programs be used to manage file permissions and ownership in PHP scripts?

FTP programs can be used to manage file permissions and ownership in PHP scripts by connecting to the server using FTP credentials, then using FTP functions to change the permissions and ownership of files on the server. This can be useful for managing file security and ensuring that only authorized users can access or modify certain files.

<?php
$ftp_server = "ftp.example.com";
$ftp_username = "username";
$ftp_password = "password";

$ftp_connection = ftp_connect($ftp_server);
$login = ftp_login($ftp_connection, $ftp_username, $ftp_password);

if ($login) {
    // Change file permissions
    ftp_chmod($ftp_connection, 0644, "example_file.php");
    
    // Change file ownership
    ftp_chown($ftp_connection, "new_owner", "example_file.php");
    
    ftp_close($ftp_connection);
} else {
    echo "Failed to connect to FTP server";
}
?>