private function scanDirectory($directory, $recursive)
    {
        if (!$results = @scandir($this->getUrl($directory))) {
            return false;
        }

        $files       = array();
        $directories = array();

        foreach ($results as $result) {
            if (in_array($result, array('.', '..'))) {
                continue;
            }

            $filename = sprintf('%s/%s', $directory, $result);

            if (false === @scandir($this->getUrl($filename))) {
                $files[] = $filename;
            } else {
                $directories[] = $filename;

                if ($recursive) {
                    $children    = $this->scanDirectory($filename, $recursive);
                    if (is_array($children)) {
                        $files       = array_merge($files, $children[0]);
                        $directories = array_merge($directories, $children[1]);
                    }
                }
            }
        }

        return array($files, $directories);
    }
private function scanDirectory($directory, $recursive)
    {
        if (!$results = @scandir($this->getUrl($directory))) {
            return false;
        }

        $files       = array();
        $directories = array();

        foreach ($results as $result) {
            if (in_array($result, array('.', '..'))) {
                continue;
            }

            $filename = sprintf('%s/%s', $directory, $result);

            if (false === @scandir($this->getUrl($filename))) {
                $files[] = $filename;
            } else {
                $directories[] = $filename;

                if ($recursive) {
                    $children    = $this->scanDirectory($filename, $recursive);
                    if (is_array($children)) {
                        $files       = array_merge($files, $children[0]);
                        $directories = array_merge($directories, $children[1]);
                    }
                }
            }
        }

        return array($files, $directories);
    }
private function scanDirectory ( $ directory , $ recursive ) { if ( ! $ results = @ scandir ( $ this -> getUrl ( $ directory ) ) ) { return false ; } $ files = array ( ) ; $ directories = array ( ) ; foreach ( $ results as $ result ) { if ( in_array ( $ result , array ( '.' , '..' ) ) ) { continue ; } $ filename = sprintf ( '%s/%s' , $ directory , $ result ) ; if ( false === @ scandir ( $ this -> getUrl ( $ filename ) ) ) { $ files [ ] = $ filename ; } else { $ directories [ ] = $ filename ; if ( $ recursive ) { $ children = $ this -> scanDirectory ( $ filename , $ recursive ) ; if ( is_array ( $ children ) ) { $ files = array_merge ( $ files , $ children [ 0 ] ) ; $ directories = array_merge ( $ directories , $ children [ 1 ] ) ; } } } } return array ( $ files , $ directories ) ; }
Scans a directory

Unfortunately, using a (recursive) directory iterator is not possible
over SFTP: see https://bugs.php.net/bug.php?id=57378. Also, is_dir() is
unreliable and often returns false for valid directories. Therefore, I
use @scandir() instead.

@param  string  $directory
@param  Boolean $recursive

@return array
Scans a directory