Skip to content

Commit

Permalink
added deleteRecursive()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 11, 2010
1 parent 3ecf0d8 commit 47f44b4
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion ftp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ class Ftp



/**
* @param string URL ftp://...
*/
public function __construct($url = NULL)
{
if (!extension_loaded('ftp')) {
throw new /*\*/Exception("PHP extension FTP is not loaded.");
}
if ($url) {
$parts = parse_url($url);
$this->connect($parts['host'], empty($parts['port']) ? NULL : (int) $parts['port']);
$this->login($parts['user'], $parts['pass']);
$this->pasv(TRUE);
if (isset($parts['path'])) {
$this->chdir($parts['path']);
}
}
}



/**
* Magic method (do not call directly).
* @param string method name
Expand Down Expand Up @@ -184,10 +205,29 @@ public function mkDirRecursive($dir)
}
}



/**
* Recursive deletes path.
* @param string
* @return void
*/
public function deleteRecursive($path)
{
if (!$this->tryDelete($path)) {
foreach ((array) $this->nlist($path) as $file) {
if ($file !== '.' && $file !== '..') {
$this->deleteRecursive(strpos($file, '/') === FALSE ? "$path/$file" : $file);
}
}
$this->rmdir($path);
}
}

}



class FtpException extends Exception
{
}
}

0 comments on commit 47f44b4

Please sign in to comment.