diff --git a/src/FtpClient/FtpClient.php b/src/FtpClient/FtpClient.php index 48e3da7..dd069cb 100644 --- a/src/FtpClient/FtpClient.php +++ b/src/FtpClient/FtpClient.php @@ -453,8 +453,19 @@ public function remove($path, $recursive = false) try { if (@$this->ftp->delete($path) - or ($this->isDir($path) and $this->rmdir($path, $recursive))) { + or ($this->isDir($path) + and $this->rmdir($path, $recursive))) { return true; + } else { + // in special cases the delete can fail (for example, at Symfony's "r+e.gex[c]a(r)s" directory) + $newPath = preg_replace('/[^A-Za-z0-9\/]/', '', $path); + if ($this->rename($path, $newPath)) { + if (@$this->ftp->delete($newPath) + or ($this->isDir($newPath) + and $this->rmdir($newPath, $recursive))) { + return true; + } + } } return false;