How can FTP programs like WS_FTP be used to manage file permissions in PHP applications?

FTP programs like WS_FTP can be used to manage file permissions in PHP applications by connecting to the server where the files are located and changing the permissions of the files or directories as needed. This can be useful for ensuring that certain files are only accessible to specific users or groups, enhancing the security of the application.

// Connect to the FTP server
$ftp_server = 'ftp.example.com';
$ftp_username = 'username';
$ftp_password = 'password';
$ftp_connection = ftp_connect($ftp_server);
ftp_login($ftp_connection, $ftp_username, $ftp_password);

// Set file permissions
$file_path = '/path/to/file.php';
$permissions = 0644; // Example permissions (read/write for owner, read for group and others)
ftp_chmod($ftp_connection, $permissions, $file_path);

// Close the FTP connection
ftp_close($ftp_connection);