is_dir() public method

Tells whether the filename is a directory
public is_dir ( string $path ) : boolean
$path string
return boolean
 /**
  * {@inheritdoc}
  */
 public function isDirectory($remoteDirectory)
 {
     if ($this->isConnected()) {
         return $this->connection->is_dir($remoteDirectory);
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @param string $identifier
  * @param string $type
  * @return bool
  */
 public function exists($identifier, $type = self::TYPE_FILE)
 {
     if ($type === self::TYPE_FILE) {
         return $this->sftp->is_file($identifier);
     } elseif ($type === self::TYPE_FOLDER) {
         return $this->sftp->is_dir($identifier);
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @param null|string $Name
  *
  * @return SFTP\Directory[]|SFTP\File[]
  */
 public function listDirectory($Name = null)
 {
     $this->persistConnection();
     if (null === $Name) {
         $Name = $this->Connection->pwd();
     }
     $List = $this->Connection->rawlist($Name);
     $Return = array();
     foreach ($List as $Item => $Attributes) {
         if ($this->Connection->is_dir($Item)) {
             $Return[$Item] = new Directory($this, $Attributes);
         }
         if ($this->Connection->is_file($Item)) {
             $Return[$Item] = new File($this, $Attributes);
         }
     }
     return $Return;
 }
Esempio n. 4
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::sync()
  * @param  \phpbu\App\Backup\Target $target
  * @param  \phpbu\App\Result        $result
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function sync(Target $target, Result $result)
 {
     // silence phpseclib
     $old = error_reporting(0);
     $sftp = new phpseclib\Net\SFTP($this->host);
     if (!$sftp->login($this->user, $this->password)) {
         error_reporting($old);
         throw new Exception(sprintf('authentication failed for %s@%s%s', $this->user, $this->host, empty($this->password) ? '' : ' with password ****'));
     }
     error_reporting($old);
     $remoteFilename = $target->getFilename();
     $localFile = $target->getPathname();
     if ('' !== $this->remotePath) {
         $remoteDirs = explode('/', $this->remotePath);
         foreach ($remoteDirs as $dir) {
             if (!$sftp->is_dir($dir)) {
                 $result->debug(sprintf('creating remote dir \'%s\'', $dir));
                 $sftp->mkdir($dir);
             }
             $result->debug(sprintf('change to remote dir \'%s\'', $dir));
             $sftp->chdir($dir);
         }
     }
     $result->debug(sprintf('store file \'%s\' as \'%s\'', $localFile, $remoteFilename));
     $result->debug(sprintf('last error \'%s\'', $sftp->getLastSFTPError()));
     /** @noinspection PhpInternalEntityUsedInspection */
     if (!$sftp->put($remoteFilename, $localFile, phpseclib\Net\SFTP::SOURCE_LOCAL_FILE)) {
         throw new Exception(sprintf('error uploading file: %s - %s', $localFile, $sftp->getLastSFTPError()));
     }
 }