What is the purpose of the ftp_chmod() function in PHP?

The ftp_chmod() function in PHP is used to change the permissions of a file on a remote FTP server. This can be useful when you need to modify the access permissions of a file to restrict or allow certain actions. By using ftp_chmod(), you can set the desired permissions for the file, such as read, write, and execute permissions for the owner, group, and others.

// Connect to FTP server
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

// Change permissions of a file on the remote server
$file_path = '/path/to/file.txt';
$permissions = 0644; // Example: read and write for owner, read for group and others
if (ftp_chmod($conn_id, $permissions, $file_path)) {
    echo "Permissions changed successfully for file: $file_path";
} else {
    echo "Failed to change permissions for file: $file_path";
}

// Close FTP connection
ftp_close($conn_id);