As stated here https://bugs.php.net/bug.php?id=55701 the count() method can lead to errors.
For example this won't works if no files are found in the target directory :
<?php
$iterator = new \GlobIterator($ftpDirectory . '/*.*', FilesystemIterator::KEY_AS_FILENAME);
if($iterator->count()) {
foreach($iterator as $filePath) {
// do some stuff ...
}
}
?>
A workaround to this bug could be :
<?php
foreach(new \GlobIterator($ftpDirectory . '/*.*', FilesystemIterator::KEY_AS_FILENAME) as $filePath) {
// do some stuff ...
}
?>