/** * @param string $file */ private function clean($file) { if (ftp_size($this->connection, $file) == -1) { $result = ftp_nlist($this->connection, $file); foreach ($result as $childFile) { $this->clean($childFile); } ftp_rmdir($this->connection, $file); } else { ftp_delete($this->connection, $file); } }
/** * {@inheritdoc} */ protected function removeDirectoryJailed($directory) { $pwd = ftp_pwd($this->connection); if (!ftp_chdir($this->connection, $directory)) { throw new FileTransferException("Unable to change to directory @directory", NULL, array('@directory' => $directory)); } $list = @ftp_nlist($this->connection, '.'); if (!$list) { $list = array(); } foreach ($list as $item) { if ($item == '.' || $item == '..') { continue; } if (@ftp_chdir($this->connection, $item)) { ftp_cdup($this->connection); $this->removeDirectory(ftp_pwd($this->connection) . '/' . $item); } else { $this->removeFile(ftp_pwd($this->connection) . '/' . $item); } } ftp_chdir($this->connection, $pwd); if (!ftp_rmdir($this->connection, $directory)) { throw new FileTransferException("Unable to remove to directory @directory", NULL, array('@directory' => $directory)); } }
function mrmdir($directory) { if (!$this->conn_id) { return false; } return @ftp_rmdir($this->conn_id, $directory); }
public function rmdir($dir) { if (FALSE === ftp_rmdir($this->link, $dir)) { $this->errormsg = "Can't remove this dir"; return FALSE; } return TRUE; }
public function deleteFolder(string $path) : bool { if (ftp_rmdir($this->connect, $path)) { return true; } else { throw new FolderNotFoundException($path); } }
/** * Updates Varien's method that accepts the $recursive param but doesn't do anything * with it. This new method calls rmdirRecursive() if $recursive is true. * * @param string $dir * @param bool $recursive * @return boolean */ public function rmdir($dir, $recursive = false) { if ($recursive) { return $this->rmdirRecursive($dir); } else { return @ftp_rmdir($this->_conn, $dir); } }
/** * Recursively delete the files in a directory via FTP. * * @author Aidan Lister <*****@*****.**> * @version 1.0.0 * @link http://aidanlister.com/2004/04/recursively-deleting-directories-via-ftp/ * @param resource $ftp_stream The link identifier of the FTP connection * @param string $directory The directory to delete */ function ftp_rmdirr($ftp_stream, $directory) { // Sanity check if (!is_resource($ftp_stream) || get_resource_type($ftp_stream) !== 'FTP Buffer') { return false; } // Init $i = 0; $files = array(); $folders = array(); $statusnext = false; $currentfolder = $directory; // Get raw file listing $list = ftp_rawlist($ftp_stream, $directory, true); // Iterate listing foreach ($list as $current) { // An empty element means the next element will be the new folder if (empty($current)) { $statusnext = true; continue; } // Save the current folder if ($statusnext === true) { $currentfolder = substr($current, 0, -1); $statusnext = false; continue; } // Split the data into chunks $split = preg_split('[ ]', $current, 9, PREG_SPLIT_NO_EMPTY); $entry = $split[8]; $isdir = $split[0][0] === 'd' ? true : false; // Skip pointers if ($entry === '.' || $entry === '..') { continue; } // Build the file and folder list if ($isdir === true) { $folders[] = $currentfolder . '/' . $entry; } else { $files[] = $currentfolder . '/' . $entry; } } // Delete all the files foreach ($files as $file) { ftp_delete($ftp_stream, $file); } // Delete all the directories // Reverse sort the folders so the deepest directories are unset first rsort($folders); foreach ($folders as $folder) { ftp_rmdir($ftp_stream, $folder); } // Delete the final folder and return its status return ftp_rmdir($ftp_stream, $directory); }
function ftp_rdel($handle, $path) { if (@ftp_delete($handle, $path) === false) { if ($children = @ftp_nlist($handle, $path)) { foreach ($children as $p) { ftp_rdel($handle, $p); } } @ftp_rmdir($handle, $path); } }
public function del($file, $recursive = false) { if (!$recursive) { return @ftp_delete($this->stream, $file); } if (!@ftp_delete($this->stream, $file)) { foreach ($this->ls($file) as $item) { $this->del($item, $recursive); } @ftp_rmdir($this->stream, $file); } }
function deleteDirUndFiles($conn_id, $pfad) { $return = @ftp_chdir($conn_id, $pfad); $file_list = ftp_nlist($conn_id, ""); foreach ($file_list as $file) { if ($file == "." || $file == "..") { //echo "nix"; } else { $return = @ftp_delete($conn_id, $pfad . $file); } } $return = @ftp_rmdir($conn_id, $pfad); }
function mappa_torles($mappa, $hova, $id) { if (!(ftp_rmdir($id, "{$hova}/{$mappa}") || ftp_delete($id, "{$hova}/{$mappa}"))) { $list = ftp_nlist($id, "{$hova}/{$mappa}"); if (!empty($list)) { foreach ($list as $ezeket) { mappa_torles($ezeket, "", $id); } } } ftp_rmdir($id, "{$hova}/{$mappa}"); return header("Location:{$PHP_SELF}?mit=" . urlencode($hova)); }
public function removeDir($ftp_folder, $path, $ftp) { $directories = explode('/', $path); foreach ($directories as $directory) { $files = ftp_nlist($ftp, $ftp_folder . $path); if (count($files) > 2) { break; } if (count($files) == 2) { ftp_rmdir($ftp, $ftp_folder . $path); str_replace('/' . $directory, '', $path); } } }
public function deleteDirectory($remoteDir) { // Require a connection and a login $this->validateState(); $remoteDir = $this->buildAbsolutePath($remoteDir); foreach ($this->listDirectory($remoteDir) as $item) { switch ($item['type']) { case 'file': $this->deleteFile("{$remoteDir}/{$item['name']}"); break; case 'directory': $this->deleteDirectory("{$remoteDir}/{$item['name']}"); break; } } @ftp_rmdir($this->ftpResource, $remoteDir); }
public function ftp_rdel($path) { if (@ftp_delete($this->ftp, $path) === false) { $list = str_replace(' ', '\\ ', str_replace('\\ ', ' ', $path)); if ($children = @ftp_nlist($this->ftp, $list . DIRECTORY_SEPARATOR)) { foreach ($children as $p) { if ($p != '.' && $p != '..') { $tmp = $path . DIRECTORY_SEPARATOR . $p; $this->ftp_rdel($tmp); } } } if (!@ftp_rmdir($this->ftp, $path . DIRECTORY_SEPARATOR)) { $this->error .= 'Não foi possível remover ' . $path . '<br>'; } } return $this->error; }
function rmAll($dst_dir, $debug = 0) { if (!$dst_dir) { return false; exit; } $dst_dir = preg_replace("/\\/\$/", "", $dst_dir); // remove trailing slash $ar_files = ftp_nlist($this->conn_id, $dst_dir); if (is_array($ar_files)) { // makes sure there are files if (count($ar_files) == 1) { // if its only a file return ftp_delete($this->conn_id, $ar_files[0]); } else { foreach ($ar_files as $st_file) { // for each file if ($st_file == "." || $st_file == "..") { continue 1; } $fl_file = "{$dst_dir}/{$st_file}"; $ftp_size = ftp_size($this->conn_id, $fl_file); if ($ftp_size == -1) { // check if it is a directory $this->rmAll($fl_file); // if so, use recursion } else { if ($debug) { echo "File: {$fl_file} | {$ftp_size}\n"; } else { ftp_delete($this->conn_id, $fl_file); } // if not, delete the file } } } } if ($debug) { echo "Dir: {$dst_dir} \n"; } elseif (count($ar_files) != 1) { echo @ftp_rmdir($this->conn_id, $dst_dir) ? "{$dst_dir} deleted!\n" : "Can't remove {$dst_dir}: No such file or directory"; } // delete empty directories }
function recursive_delete($ftp, $path) { $files = ftp_rawlist($ftp, $path); foreach ($files as $file) { $i = explode(' ', $file); $filename = $i[count($i) - 1]; if (strpos($file, '<DIR>') !== false) { recursive_delete($ftp, $path . '/' . $filename); } else { if (!ftp_delete($ftp, $path . '/' . $filename)) { return false; } } } if (!ftp_rmdir($ftp, $path)) { return false; } return true; }
static function TestFTPDir($conn_id, $file, $testDir) { $success = false; ftp_chdir($conn_id, '/'); $random_name = 'gpeasy_random_' . rand(1000, 9999); $random_full = rtrim($file, '/') . '/' . $random_name; $test_full = rtrim($testDir, '/') . '/' . $random_name; ob_start(); if (!@ftp_mkdir($conn_id, $random_full)) { ob_end_clean(); return false; } ob_end_clean(); if (file_exists($test_full)) { $success = true; } ftp_rmdir($conn_id, $random_full); return $success; }
/** * preprocess Index action. * * @access public * @return string Forward name (null if no errors.) */ function prepare() { if ($this->af->validate() == 0) { $username = $this->af->get('ftp_username'); $password = $this->af->get('ftp_password'); if ($conn_id = ftp_connect('localhost')) { if (ftp_login($conn_id, $username, $password)) { $ftp_root = $this->seekFTPRoot($conn_id); if ($ftp_root !== false) { $chroot = substr(BASE, strlen($ftp_root)); $tmp_file = $chroot . '/tmp/tmp_file'; $tmp_dir = $chroot . '/tmp/tmp_dir'; $pwd = ftp_pwd($conn_id); if (ftp_put($conn_id, $tmp_file, __FILE__, FTP_BINARY)) { if (ftp_delete($conn_id, $tmp_file)) { if (ftp_mkdir($conn_id, $tmp_dir)) { if (ftp_rmdir($conn_id, $tmp_dir)) { return null; } else { $this->ae->add('ftp_rmdir', _('Failed ftp operation rmdir.')); } } else { $this->ae->add('ftp_mkdir', _('Failed ftp operation mkdir.')); } } else { $this->ae->add('ftp_delete', _('Failed ftp operation delete.')); } } else { $this->ae->add('ftp_put', _('Failed ftp operation put.') . sprintf('[debug] pwd=>%s, __FILE__=>%s', $pwd, __FILE__)); } } else { $this->ae->add('ftp_root_path', _('Failed seek ftp root path.')); } } else { $this->ae->add('ftp_login', _('FTP login failed.')); } } else { $this->ae->add('ftp_connect', _('Failed ftp connect to localhost.')); } } return 'json_error'; }
function ftp_rrmdir($ftp_stream, $directory) { $rrmdir = function ($ftp_stream, $directory) { $cwd = ftp_pwd($ftp_stream); if (@ftp_chdir($ftp_stream, $directory)) { $nlist = ftp_nlist($ftp_stream, '.'); if ($nlist) { foreach ($nlist as $file) { ftp_rrmdir($ftp_stream, $file); } } ftp_chdir($ftp_stream, $cwd); $ok = @ftp_rmdir($ftp_stream, $directory); } else { $ok = @ftp_delete($ftp_stream, $directory); } return $ok; }; return $rrmdir($ftp_stream, $directory); }
protected function _deleteDirectory($sPath) { if ($this->_isDirectory($sPath)) { if (substr($sPath, -1) != '/') { $sPath .= '/'; } if (($aFiles = @ftp_nlist($this->_rStream, $sPath)) !== false) { foreach ($aFiles as $sFile) { if ($sFile != '.' && $sFile != '..') { $this->_deleteDirectory(false === strpos($sFile, '/') ? $sPath . $sFile : $sFile); } } } if (!@ftp_rmdir($this->_rStream, $sPath)) { return false; } } else { if (!@ftp_delete($this->_rStream, $sPath)) { return false; } } return true; }
$sessionUpdated = true; } if ($action != 'newlogin') { if (!count($connInfo)) { $connInfo = getConnectionInfo(); } $ftp = @phpftp_connect($connInfo['ftpserver'], $connInfo['username'], $connInfo['password']); if ($ftp) { $homedir = ftp_pwd($ftp); $retval = ftp_pasv($ftp, 1); if ($action == 'delete' || $action == 'rmdir') { if ($_POST['confirm']) { if ($action == 'delete') { $retval = @ftp_delete($ftp, $olddir . '/' . $file); } else { $retval = @ftp_rmdir($ftp, $olddir . '/' . $file); } if ($retval) { $GLOBALS['phpgw']->template->set_var("misc_data", lang('Successfully deleted %1', "{$olddir}/{$file}"), true); } else { $GLOBALS['phpgw']->template->set_var('misc_data', lang('failed to delete %1', "{$olddir}/{$file}"), true); } } else { if (!$_POST['cancel']) { $GLOBALS['phpgw']->template->set_var('misc_data', confirmDeleteForm($session, $file, $olddir), true); } } } if ($action == 'rename') { if ($confirm) { if (ftp_rename($ftp, $olddir . '/' . $filename, $olddir . '/' . $newfilename)) {
function ftp_rmdir($directory) { $directory = discuz_ftp::clear($directory); return @ftp_rmdir($this->connectid, $directory); }
function ftp_rmdir2($conn_id, $directory) { // -------------- // This function deletes a directory // -------------- // Replace \' by \\' to be able to delete directories with names containing \' $directory = str_replace("\\'", "\\\\'", $directory); // QUICK WAY TO DELETE A DIRECTORY $success1 = ftp_rmdir($conn_id, $directory); // THE FTP_RMDIR MAY NOT WORK WITH ALL FTP SERVERS, AS DESCRIBED ON THE FORUM // http://www.net2ftp.org/forums/index.php?showtopic=658 // Solution: to delete /dir/parent/dirtodelete // 1. chdir to the parent directory /dir/parent // 2. delete the subdirectory, but use only its name (dirtodelete), not the full path (/dir/parent/dirtodelete) if ($success1 == false) { ftp_chdir($conn_id, upDir($directory)); $parts = explode("/", $directory); $lastpartnr = sizeof($parts) - 1; $success2 = ftp_rmdir($conn_id, $parts[$lastpartnr]); if ($success2 == false) { $errormessage = __("Unable to delete the directory <b>%1\$s</b>", $directory); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } } }
/** * Remove dir * * @param string $path dir path * @return bool * @author Dmitry (dio) Levashov **/ protected function _rmdir($path) { return ftp_rmdir($this->connect, $path); }
/** * @inheritdoc */ public function deleteDir($dirname) { $connection = $this->getConnection(); $contents = array_reverse($this->listDirectoryContents($dirname)); foreach ($contents as $object) { if ($object['type'] === 'file') { if (!ftp_delete($connection, $object['path'])) { return false; } } elseif (!ftp_rmdir($connection, $object['path'])) { return false; } } return ftp_rmdir($connection, $dirname); }
/** * 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); $list = $this->list_files($filepath); if ($list !== FALSE) { foreach ($list as $item) { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() if (!@ftp_delete($this->conn_id, $item)) { $this->delete_dir($item); } } } $result = @ftp_rmdir($this->conn_id, $filepath); if ($result === FALSE) { if ($this->debug == TRUE) { $this->_error('ftp_unable_to_delete'); } return FALSE; } return TRUE; }
/** * Method to delete a path [file/folder] on the FTP server * * @access public * @param string $path Path to delete * @return boolean True if successful */ function delete($path) { // If native FTP support is enabled lets use it... if (FTP_NATIVE) { if (@ftp_delete($this->_conn, $path) === false) { if (@ftp_rmdir($this->_conn, $path) === false) { JError::raiseWarning('35', 'JFTP::delete: Bad response'); return false; } } return true; } // Send delete file command and if that doesn't work, try to remove a directory if (!$this->_putCmd('DELE ' . $path, 250)) { if (!$this->_putCmd('RMD ' . $path, 250)) { JError::raiseWarning('35', 'JFTP::delete: Bad response', 'Server response: ' . $this->_response . ' [Expected: 250] Path sent: ' . $path); return false; } } return true; }
/** * 删除文件夹 * * @access public * @param string 目录标识(ftp) * @return boolean */ public function delete_dir($path) { if (!$this->_isconn()) { return FALSE; } //对目录宏的'/'字符添加反斜杠'\' $path = preg_replace("/(.+?)\\/*\$/", "\\1/", $path); //获取目录文件列表 $filelist = $this->filelist($path); if ($filelist !== FALSE and count($filelist) > 0) { foreach ($filelist as $item) { //如果我们无法删除,那么就可能是一个文件夹 //所以我们递归调用delete_dir() if (!@delete_file($item)) { $this->delete_dir($item); } } } //删除文件夹(空文件夹) $result = @ftp_rmdir($this->conn_id, $path); if ($result === FALSE) { if ($this->debug === TRUE) { $this->_error("ftp_unable_to_delete_dir:dir[" . $path . "]"); } return FALSE; } return TRUE; }
private function deleteRecursive($path) { $handle = $this->fileSystem->getConnection(); $files = array(); $dirs = array(); $lines = ftp_rawlist($handle, $path); foreach ($lines as $line) { $matches = null; $unixRe = '/^([\\-ld])((?:[\\-r][\\-w][\\-xs]){3})\\s+(\\d+)\\s+(\\w+)\\s+([\\-\\w]+)\\s+(\\d+)\\s+(\\w+\\s+\\d+\\s+[\\w:]+)\\s+(.+)$/'; $windowsRe = "/^([^\\s]+\\s+[^\\s]+)\\s+((?:<DIR>|[\\w]+)?)\\s+(.+)\$/"; if (preg_match($unixRe, $line, $matches)) { $filePath = MOXMAN_Util_PathUtils::combine($path, $matches[8]); if ($matches[1] === "d") { $dirs[] = $filePath; } else { $files[] = $filePath; } } else { if (preg_match($windowsRe, $line, $matches)) { $filePath = MOXMAN_Util_PathUtils::combine($path, $matches[3]); if ($matches[2] === "<DIR>") { $dirs[] = $filePath; } else { $files[] = $filePath; } } else { // Unknown format throw new MOXMAN_Exception("Unknown FTP list format: " . $line); } } } // Delete files in dir foreach ($files as $file) { ftp_delete($handle, $file); } // Delete directories in dir foreach ($dirs as $dir) { $this->deleteRecursive($dir); } // Delete dir ftp_rmdir($handle, $path); }
public function rmdir($remote_directory) { $remote_directory = $this->get_absolute_path($remote_directory); if ($this->debug) { echo "Suppression du dossier {$remote_directory}\n<br>"; } if (@ftp_rmdir($this->connexion, $remote_directory) === false) { throw new Exception('Impossible de supprimer le dossier'); } unset($this->cached_dirs[$remote_directory]); return $this; }