elFinderVolumeFTP::ftp_scan_dir PHP Method

ftp_scan_dir() protected method

Gets an array of absolute remote FTP paths of files and folders in $remote_directory omitting symbolic links.
protected ftp_scan_dir ( $remote_directory, $targets = null ) : array
$remote_directory string remote FTP path to scan for file and folders recursively
$targets array Array of target item. `null` is to get all of items
return array of elements each of which is an array of two elements:
  • $item['path'] - absolute remote FTP path
  • $item['type'] - either 'f' for file or 'd' for directory
    protected function ftp_scan_dir($remote_directory, $targets = null)
    {
        $buff = ftp_rawlist($this->connect, $remote_directory);
        $items = array();
        if ($targets && is_array($targets)) {
            $targets = array_flip($targets);
        } else {
            $targets = false;
        }
        foreach ($buff as $str) {
            $info = preg_split("/\\s+/", $str, 9);
            if (!isset($this->ftpOsUnix)) {
                $this->ftpOsUnix = !preg_match('/\\d/', substr($info[0], 0, 1));
            }
            if (!$this->ftpOsUnix) {
                $info = $this->normalizeRawWindows($str);
            }
            $type = substr($info[0], 0, 1);
            $name = trim($info[8]);
            if ($name !== '.' && $name !== '..' && (!$targets || isset($targets[$name]))) {
                switch ($type) {
                    case 'l':
                        //omit symbolic links
                    //omit symbolic links
                    case 'd':
                        $remote_file_path = $this->_joinPath($remote_directory, $name);
                        $item = array();
                        $item['path'] = $remote_file_path;
                        $item['type'] = 'd';
                        // normal file
                        $items[] = $item;
                        $items = array_merge($items, $this->ftp_scan_dir($remote_file_path));
                        break;
                    default:
                        $remote_file_path = $this->_joinPath($remote_directory, $name);
                        $item = array();
                        $item['path'] = $remote_file_path;
                        $item['type'] = 'f';
                        // normal file
                        $items[] = $item;
                }
            }
        }
        return $items;
    }