/** * {@inheritdoc} */ public function getDirectoryContentsList($remoteDirectory) { if ($this->isConnected()) { $contentsList = array_values(array_diff($this->connection->nlist($remoteDirectory), array('.', '..'))); sort($contentsList); return $contentsList; } return array(); }
/** * @param string $identifier * @param bool $files * @param bool $folders * @param bool $recursive * @return array */ public function scanDirectory($identifier, $files = true, $folders = true, $recursive = false) { $directoryEntries = []; if (!$files && !$folders) { return $directoryEntries; } $items = $this->sftp->nlist($identifier, $recursive); foreach ($items as $item) { if ($item === '.' || $item === '..') { continue; } $itemIdentifier = $identifier . $item; if ($files && $this->sftp->is_file($itemIdentifier)) { $directoryEntries[$itemIdentifier] = $this->getShortInfo($identifier, 'file'); } elseif ($folders && $this->sftp->is_dir($itemIdentifier)) { $directoryEntries[$itemIdentifier] = $this->getShortInfo($identifier, 'dir'); } } return $directoryEntries; }
public function exists($path) { if (false === $this->isConnected()) { $this->connectAndLogin(); } $pwd = $this->sftp->pwd(); // try to change directory to see if it is an existing directory $result = $this->sftp->chdir($path); if (true === $result) { $result = $this->sftp->chdir($pwd); // change back to the original directory return true; } else { // list the parent directory and check if the file exists $parent = dirname($path); $result = $this->sftp->nlist($parent); if (false !== $result) { if (in_array(basename($path), $result)) { return true; } } } return false; }