Ejemplo n.º 1
0
 /**
  * @param $filename
  */
 public function delete($filename)
 {
     if ($this->isDir($filename)) {
         ssh2_sftp_rmdir($this->getSftpResource(), $filename);
     } else {
         ssh2_sftp_unlink($this->getSftpResource(), $filename);
     }
 }
Ejemplo n.º 2
0
 public function remove($remote)
 {
     $sftp = ssh2_sftp($this->conn_);
     $rc = false;
     if (is_dir("ssh2.sftp://{$sftp}/{$remote}")) {
         $rc = ssh2_sftp_rmdir($sftp, $remote);
     } else {
         $rc = ssh2_sftp_unlink($sftp, $remote);
     }
     return $rc;
 }
Ejemplo n.º 3
0
 public function delete($file, $recursive = false)
 {
     if ($this->is_file($file)) {
         return ssh2_sftp_unlink($this->sftp, $file);
     }
     if (!$recursive) {
         return ssh2_sftp_rmdir($this->sftp, $file);
     }
     $filelist = $this->getdir($file);
     if (is_array($filelist)) {
         foreach ($filelist as $filename => $fileinfo) {
             $this->delete($file . '/' . $filename, $recursive);
         }
     }
     return ssh2_sftp_rmdir($this->sftp, $file);
 }
Ejemplo n.º 4
0
 /**
  * Remove Directory
  *
  * @param string $path Path to remove
  * @return Object
  */
 function _removeDir_real($path)
 {
     if (substr($path, 0, 2) == "./") {
         $path = substr($path, 2);
     }
     $target_path = $this->ftp_info->ftp_root_path . $path;
     if (!@ssh2_sftp_rmdir($this->sftp, $target_path)) {
         return new Object(-1, sprintf(Context::getLang('msg_delete_dir_failed'), $path));
     }
     return new Object();
 }
Ejemplo n.º 5
0
 /**
  * @{inheritDoc}
  */
 public function rmdir($dirname = '')
 {
     return $this->doRun(__METHOD__, func_get_args(), ssh2_sftp_rmdir($this->sftp, $dirname));
 }
Ejemplo n.º 6
0
 public function rmdir($directory)
 {
     $check = '/' . trim($this->dir, '/') . '/' . trim($directory, '/');
     return @ssh2_sftp_rmdir($this->handle, $check);
 }
Ejemplo n.º 7
0
 /**
  * Deletes a remote file.
  *
  * @param string  $remote_path
  * @param boolean $recursive
  *
  * @return boolean Returns TRUE on success or FALSE on error
  *
  * @throws \BackBee\Util\Transport\Exception\TransportException Occures if SSH connection is invalid
  */
 public function delete($remote_path, $recursive = false)
 {
     if (null === $this->_sftp_resource) {
         throw new TransportException(sprintf('None SSH connection available.'));
     }
     if (true === $recursive) {
         // @todo
         throw new TransportException(sprintf('REcursive option not implemented yet.'));
     }
     $remote_path = $this->_getAbsoluteRemotePath($remote_path);
     if (false === @ssh2_sftp_stat($this->_sftp_resource, $remote_path)) {
         return $this->_trigger_error(sprintf('Remote file to delete does not exist: %s.', $remote_path));
     }
     if (false === ssh2_sftp_unlink($this->_sftp_resource, $remote_path)) {
         return ssh2_sftp_rmdir($this->_sftp_resource, $remote_path);
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * @param string $identifier
  * @param bool $recursive
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function delete($identifier, $recursive)
 {
     if (is_dir($this->sftpWrapper . $identifier)) {
         return ssh2_sftp_rmdir($this->sftp, $identifier);
     } elseif (is_file($this->sftpWrapper . $identifier)) {
         return ssh2_sftp_unlink($this->sftp, $identifier);
     } else {
         return false;
     }
 }
Ejemplo n.º 9
0
 /**
  * Delete a folder and recursively delete everything (including sub-folders)
  * containted within it.
  *
  * @access	public
  * @param	string
  * @return	bool
  */
 function delete_dir($filepath)
 {
     if (!$this->_is_conn()) {
         return FALSE;
     }
     // Add a trailing slash to the file path if needed
     $filepath = preg_replace("/(.+?)\\/*\$/", "\\1/", $filepath);
     $result = @ssh2_sftp_rmdir($this->conn_id, $filepath);
     if ($result === FALSE) {
         $this->_error('sftp_unable_to_delete');
         return FALSE;
     }
     return TRUE;
 }
Ejemplo n.º 10
0
 function ssh2RemoveDirectory($directory)
 {
     $result = ssh2_sftp_rmdir($this->sftp, $directory);
     return $result;
 }
Ejemplo n.º 11
0
 /**
  * Deletes an item on the SFTP server
  *
  * @author Art <*****@*****.**>
  *
  * @param string $item File or directory name
  *
  * @return boolean
  */
 function delete($item)
 {
     $this->checkSubsystem();
     $path = $this->resolvePath($item);
     if (self::isFile($item)) {
         $success = ssh2_sftp_unlink($this->sftp, $path);
     } else {
         $success = ssh2_sftp_rmdir($this->sftp, $path);
     }
     if ($success) {
         \Log::debug('Deleted ' . $item);
         return true;
     } else {
         \Log::error('Failed to delete ' . $item);
         return false;
     }
 }
Ejemplo n.º 12
0
 /**
  * [deleteDir description]
  * @param  [type] $path [description]
  * @return [type]       [description]
  */
 public function deleteDir($path)
 {
     if (false === $this->validConn()) {
         throw new Exception('invalid connection');
     }
     if (!($this->sftp = @ssh2_sftp($this->conn))) {
         throw new Exception("unable to establish sftp connection with {$host}");
     }
     return $this->sftp;
     // Add a trailing slash to the file path if needed
     $filepath = preg_replace("/(.+?)\\/*\$/", "\\1/", $path);
     $list = $this->fileList($path);
     if (count($list) > 0) {
         foreach ($list as $item) {
             if (!@ssh2_sftp_rmdir($this->sftp, $item)) {
                 $this->deleteDir($item);
             }
         }
     }
     return true;
 }
Ejemplo n.º 13
0
 /** 
  * Delete a directory and return true/false according to success.
  * Wrapping ssh2_exec
  * 
  * (non-PHPdoc)
  * @see kFileTransferMgr::doDelDir()
  */
 protected function doDelDir($remotePath)
 {
     return ssh2_sftp_rmdir($this->getSftpConnection(), $remotePath);
 }
Ejemplo n.º 14
0
 public function rmdir($dirname)
 {
     return ssh2_sftp_rmdir($this->_sftp, $dirname);
 }
Ejemplo n.º 15
0
 /**
  * Removes a directory
  *
  * @param  string $dirname The directory that is being removed
  *
  * @return Boolean TRUE on success, or FALSE on failure
  */
 public function rmdir($dirname)
 {
     return ssh2_sftp_rmdir($this->getResource(), $dirname);
 }
Ejemplo n.º 16
0
 /**
  * Recursively remove a directory and all its subdirectories.
  *
  * Walks a directory structure, removing files recursively. An optional
  * exclusion pattern can be included. If a directory contains a file that
  * matches the exclusion pattern, the directory and its ancestors will not
  * be deleted.
  *
  * @param string $path
  * @param string $noDelPat PCRE pattern for excluding files in deletion.
  */
 public static function rrmdir($path, $noDelPat = null)
 {
     $useExclude = $noDelPat != null;
     $special = '/.*\\/?\\.+\\/?$/';
     $excluded = false;
     if (!realpath($path)) {
         return false;
     }
     $path = realpath($path);
     if (filetype($path) == 'dir') {
         $objects = scandir($path);
         foreach ($objects as $object) {
             if (!preg_match($special, $object)) {
                 if ($useExclude) {
                     if (!preg_match($noDelPat, $object)) {
                         $excludeThis = self::rrmdir($path . DIRECTORY_SEPARATOR . $object, $noDelPat);
                         $excluded = $excluded || $excludeThis;
                     } else {
                         $excluded = true;
                     }
                 } else {
                     self::rrmdir($path . DIRECTORY_SEPARATOR . $object, $noDelPat);
                 }
             }
         }
         reset($objects);
         if (!$excluded) {
             if (!preg_match($special, $path)) {
                 switch (self::$fileOper) {
                     case 'ftp':
                         $path = self::ftpStripChroot($path);
                         ftp_rmdir(self::$_ftpStream, $path);
                         break;
                     case 'scp':
                         ssh2_sftp_rmdir(ssh2_sftp(self::$_sshStream), $path);
                         break;
                     case 'php':
                     default:
                         rmdir($path);
                 }
             }
         }
     } else {
         switch (self::$fileOper) {
             case 'ftp':
                 $path = self::ftpStripChroot($path);
                 ftp_delete(self::$_ftpStream, $path);
                 break;
             case 'scp':
                 ssh2_sftp_unlink(ssh2_sftp(self::$_sshStream), $path);
                 break;
             case 'php':
             default:
                 unlink($path);
         }
     }
     return $excluded;
 }
Ejemplo n.º 17
0
 public function deleteFolder(string $path) : bool
 {
     if (@ssh2_sftp_rmdir($this->connect, $path)) {
         return true;
     } else {
         throw new FolderNotFoundException($path);
     }
 }
Ejemplo n.º 18
0
 /**
  * @see Filesystem::delete
  */
 public function delete($path, $recursive = false)
 {
     if ($this->isFile($path)) {
         return ssh2_sftp_unlink($this->sftp_link, $path);
     }
     if (!$recursive) {
         return ssh2_sftp_rmdir($this->sftp_link, $path);
     }
     $filelist = $this->listDir($path);
     if (is_array($filelist)) {
         foreach ($filelist as $filename => $fileinf) {
             $this->delete($path . '/' . $filename, $recursive);
         }
     }
     return ssh2_sftp_rmdir($this->sftpConnection, $path);
 }
Ejemplo n.º 19
0
 /**
  * Delete a folder and recursively delete everything (including sub-folders)
  * containted within it.
  *
  * @version 1.0
  * @access  public
  * @param   string
  * @return  bool
  */
 public function delete_dir($filepath)
 {
     if (!$this->_is_conn()) {
         return FALSE;
     }
     // Add a trailing slash to the file path if needed
     $filepath = preg_replace("/(.+?)\\/*\$/", "\\1/", $filepath);
     $list = $this->list_files($filepath);
     if ($list !== FALSE and count($list) > 0) {
         foreach ($list as $item) {
             // If we can't delete the item it's probaly a folder so
             // we'll recursively call delete_dir()
             if (!@ssh2_sftp_rmdir($this->sftp, $item)) {
                 $this->delete_dir($item);
             }
         }
     }
     $result = @ssh2_sftp_rmdir($this->sftp, $filepath);
     if ($result === FALSE) {
         if ($this->debug == TRUE) {
             $this->_error('ftp_unable_to_delete');
         }
         return FALSE;
     }
     return TRUE;
 }
Ejemplo n.º 20
0
 /**
  * Deletes a folder from the VFS.
  *
  * @param string $path        The parent folder.
  * @param string $name        The name of the folder to delete.
  * @param boolean $recursive  Force a recursive delete?
  *
  * @throws Horde_Vfs_Exception
  */
 public function deleteFolder($path, $name, $recursive = false)
 {
     $this->_connect();
     $isDir = false;
     foreach ($this->listFolder($path) as $file) {
         if ($file['name'] == $name && $file['type'] == '**dir') {
             $isDir = true;
             break;
         }
     }
     if ($isDir) {
         $file_list = $this->listFolder($path . '/' . $name);
         if (count($file_list) && !$recursive) {
             throw new Horde_Vfs_Exception(sprintf('Unable to delete "%s", the directory is not empty.', $this->_getPath($path, $name)));
         }
         foreach ($file_list as $file) {
             if ($file['type'] == '**dir') {
                 $this->deleteFolder($path . '/' . $name, $file['name'], $recursive);
             } else {
                 $this->deleteFile($path . '/' . $name, $file['name']);
             }
         }
         if (!@ssh2_sftp_rmdir($this->_sftp, $this->_getPath($path, $name))) {
             throw new Horde_Vfs_Exception(sprintf('Cannot remove directory "%s".', $this->_getPath($path, $name)));
         }
     } else {
         if (!@ssh2_sftp_unlink($this->_sftp, $this->_getPath($path, $name))) {
             throw new Horde_Vfs_Exception(sprintf('Cannot delete file "%s".', $this->_getPath($path, $name)));
         }
     }
 }
Ejemplo n.º 21
0
 function SSHrmdir($DirToDelete, $recursive = false)
 {
     if ($recursive) {
         if (ssh2_exec($this->Conn, 'rm -fr ' . $this->WorkingDir . $DirToDelete)) {
             return true;
         } else {
             return false;
         }
     } elseif (!$recursive) {
         if ($sftp = ssh2_sftp($this->Conn)) {
             if (ssh2_sftp_rmdir($sftp, $this->WorkingDir . $DirToDelete)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 22
0
 /**
  * Remove a directory from remote server
  */
 public function rmdir($dirName)
 {
     $dir = $this->dir . '/' . $dirName;
     if (!ssh2_sftp_rmdir($this->_getSftp(), $dir)) {
         throw new \Exception("Could not remove directory '{$dir}'");
     }
     return true;
 }
Ejemplo n.º 23
0
 /**
  * Remove a directory if it exists.
  *
  * @param   string   $dirName    The full path of the directory to remove
  * @param   boolean  $recursive  Should I remove its contents recursively? Otherwise it will fail if the directory
  *                               is not empty.
  *
  * @return mixed
  */
 public function rmdir($dirName, $recursive = true)
 {
     if (!$recursive) {
         $targetDir = $this->translatePath($dirName);
         return @ssh2_sftp_rmdir($this->sftpHandle, $targetDir);
     } else {
         if (!is_dir($dirName)) {
             return $this->delete($dirName);
         }
         $ret = true;
         $di = new \DirectoryIterator($dirName);
         /** @var \DirectoryIterator $dirEntry */
         foreach ($di as $dirEntry) {
             if ($dirEntry->isDot()) {
                 continue;
             }
             if ($dirEntry->isFile()) {
                 $ret = $ret && $this->delete($dirEntry->getPathname());
             } elseif ($dirEntry->isDir()) {
                 $ret = $ret && $this->rmdir($dirEntry->getPathname(), true);
             }
         }
         $ret = $ret && $this->rmdir($dirName, false);
         return $ret;
     }
 }
Ejemplo n.º 24
0
 /**
  * Remote rmdir.
  *
  * @param string $dirname
  *
  * @return bool
  */
 public function rmdir($dirname)
 {
     ssh2_sftp_rmdir($this->resource, $dirname);
 }
Ejemplo n.º 25
0
 public function removeDirectory($directory, $recursive = false)
 {
     $directory = $this->path($directory);
     if ($recursive) {
         foreach ($this->directory($directory) as $child) {
             if ($child->isDirectory()) {
                 $this->removeDirectory($child->getPath(), true);
             } else {
                 $this->unlink($child->getPath());
             }
         }
     }
     // Normal
     $return = @ssh2_sftp_rmdir($this->getSftpResource(), $directory);
     if (!$return) {
         throw new Engine_Vfs_Adapter_Exception(sprintf('Unable to remove directory "%s"', $directory));
     }
     return true;
 }
Ejemplo n.º 26
0
 function delete($file, $recursive = false, $type = false)
 {
     if ('f' == $type || $this->is_file($file)) {
         return ssh2_sftp_unlink($this->sftp_link, $file);
     }
     if (!$recursive) {
         return ssh2_sftp_rmdir($this->sftp_link, $file);
     }
     $filelist = $this->dirlist($file);
     if (is_array($filelist)) {
         foreach ($filelist as $filename => $fileinfo) {
             $this->delete($file . '/' . $filename, $recursive, $fileinfo['type']);
         }
     }
     return ssh2_sftp_rmdir($this->sftp_link, $file);
 }
Ejemplo n.º 27
0
 /**
  * Deletes a remote directory
  *
  * @param string $dirname path of the directory
  * @return bool TRUE on success or FALSE on failure
  */
 public function rmdir($dirname)
 {
     $this->connect();
     return @ssh2_sftp_rmdir($this->_sftp, $dirname);
 }