How can PHP be used to automate the process of creating folders with specific permissions in an FTP server?

To automate the process of creating folders with specific permissions in an FTP server using PHP, you can use the FTP functions provided by PHP. You can connect to the FTP server, create a directory with the desired permissions, and then set the permissions using the `chmod` function.

<?php
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';

$dir = '/path/to/new/directory';
$permissions = 0755;

// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

// Create directory
if (ftp_mkdir($conn_id, $dir)) {
    echo "Directory created successfully\n";
} else {
    echo "Failed to create directory\n";
}

// Set directory permissions
if (ftp_chmod($conn_id, $permissions, $dir)) {
    echo "Permissions set successfully\n";
} else {
    echo "Failed to set permissions\n";
}

// Close FTP connection
ftp_close($conn_id);
?>