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); }
function remove($path) { $this->sessionSuspend(); try { $ftp = $this->getConnection(); $splitPaths = Path::split($path); $name = array_pop($splitPaths); $this->chdir($ftp, $splitPaths); if (ftp_is_dir($ftp, $name)) { include_once __DIR__ . '/../fns/ftp_rrmdir.php'; $ok = ftp_rrmdir($ftp, $name); if (!$ok) { throw new ReadWriteException($path); } } elseif (ftp_is_file($ftp, $name)) { $ok = @ftp_delete($ftp, $name); if (!$ok) { throw new ReadWriteException($path); } } else { throw new FileNotFoundException($path); } } catch (Exception $e) { $this->sessionResume(); throw $e; } $this->sessionResume(); }