How can PHP be used to differentiate between files and directories on a remote FTP server?

To differentiate between files and directories on a remote FTP server using PHP, you can use the `ftp_nlist` function to retrieve a list of files and directories, and then use the `ftp_size` function to check if an item is a file or directory based on its size. Files typically have a size greater than 0, while directories have a size of 0.

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

$ftp_connection = ftp_connect($ftp_server);
$login = ftp_login($ftp_connection, $ftp_user, $ftp_pass);

$files = ftp_nlist($ftp_connection, '/path/to/directory');

foreach($files as $file) {
    $file_size = ftp_size($ftp_connection, $file);
    if($file_size > 0) {
        echo "File: $file\n";
    } else {
        echo "Directory: $file\n";
    }
}

ftp_close($ftp_connection);
?>