I want a similar command as is_dir for FTP server

I am trying to find a function for FTP server that will resemble is_dir in PHP. It looks like ftp_nlist may do the job but it looks clumsy to me. Maybe there is another way to the result?
I don’t want to use ftp_nlist.

if ((ftp_nlist($conn_id, $dir) !== false) {
echo “It is directory”;
}
else {
echo “It is NOT directory”;
}

Well, if you use ftp_rawlist, instead of nlist, you can use this:

# Check if the file is directory.
        $isDir = ftp_size($ftpStream, $fileName) === -1 ? true : false;

If you look at php.net and the ftp_rawlist funciton, there is an example that pulls the remote directory list and shows it as directory:file and you can use this function to see which is a directory. Bascially this way, you can create an array of the recursive folder structure on the remote site.

Hope this helps…

1 Like

There’s nothing built in. This makes sense if you think about it; connecting to an FTP server is a network request which will not be as quick as a local function call, so the functions you have to work with are geared towards getting large amounts of information at once.

Hello mini_me.

I think the functionality you are thinking about might already be supported by PHP, here’s a quick browse through stack overflow:

The basic idea is to call is_dir on a ftp URL.

Well, that basically will check if the count of the folder return equals one. This should work although not really a is_dir function. But, I always think if it works, use it. So, ether way will work for you!

Sponsor our Newsletter | Privacy Policy | Terms of Service