How can FTP functions in PHP be utilized to set permissions for remote files during the upload process?

When uploading files to a remote server using FTP in PHP, you can utilize the FTP functions to set permissions for the uploaded files. This can be done by using the ftp_chmod function after the file has been uploaded to the server. By specifying the desired permissions (e.g., 0644 for read and write permissions for the owner), you can ensure that the file has the correct permissions.

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

// Upload file
ftp_put($ftp, '/remote/path/file.txt', '/local/path/file.txt', FTP_BINARY);

// Set permissions for the uploaded file
ftp_chmod($ftp, 0644, '/remote/path/file.txt');

// Close FTP connection
ftp_close($ftp);