View Full Version : file_exists not working over secure ftp.

03-07-2008, 03:22 PM
Hi all,

I have encountered a problem with file_exists when running PHP 5.2 in client mode under Debian Etch, which is best illustrated by the following code:

$remote_dir = "ftps://username:password@";
$list = scandir($remote_dir);

foreach ($list as $entry)
echo $remote_dir.$entry.(file_exists($remote_dir.$entry) ? " exists": " not found")."\n";

Now the output from this is as follows:

ftps://usename:password@ not found
ftps://usename:password@ not found
ftps://usename:password@ not found
... etc

¿Que? :confused:

EDIT: I've found that scandir, is_dir and unlink work, however file_exists, is_file, is_readable and stat don't work. Weird.

03-07-2008, 03:37 PM
Turn on full php error reporting to see if any errors are occurring.

For your code to work, two things must happen. PHP must have the OpenSSL extension enabled so that it can make a request using the ftps protocol, and the ftps wrapper must support scandir().

From the php manual it is not clear if scandir() is supported. Table O.4 does not specifically list scandir(), but it would probably fall under the stat() functions, where only the following are supported - As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(), and is_dir() elements only. As of PHP 5.1.0: filemtime().

03-07-2008, 03:42 PM

thanks for that! I will investigate my set-up more fully ... in the meantime I've written a hack using fopen and fclose.