What FTP commands can be used to check if a directory exists in PHP?

To check if a directory exists on an FTP server using PHP, you can use the FTP command "NLST" (Name List). This command will return a list of filenames in a specified directory. You can then check if the directory you are looking for is present in the list.

<?php
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$ftp_dir = '/path/to/directory';

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

if ($login) {
    $file_list = ftp_nlist($ftp_conn, $ftp_dir);
    if (in_array($ftp_dir, $file_list)) {
        echo "Directory exists";
    } else {
        echo "Directory does not exist";
    }
    ftp_close($ftp_conn);
} else {
    echo "FTP login failed";
}
?>