Exemple #1
0
Fichier : FTP.php Projet : uda/jaws
 /**
  * This changes the currently used directory
  *
  * @access  public
  * @param   string $dir  The directory to go to.
  * @return  mixed        True on success, otherwise Jaws_Error
  */
 function cd($dir)
 {
     $res = $this->_ftp->cd($dir);
     if (PEAR::isError($res)) {
         return new Jaws_Error($res->getMessage(), __FUNCTION__);
     }
     return true;
 }
Exemple #2
0
 /**
  * Purge given directory's contents
  *
  * @var string $purgeDirs
  */
 public function purge($purgeDirs)
 {
     foreach ($purgeDirs as $dir) {
         $origin = $this->connection->pwd();
         $this->output("<red>Purging directory <white>{$dir}");
         // Failing to enter into the directory means should stop
         // the script form purging. Otherwise wrong content is deleted.
         // @Agnis-LV lost ~8GB of important data because of this. Sorry man!
         if (!$this->connection->cd($dir)) {
             $this->output(" ! Could not enter into '{$dir}'. Check your directory path.");
             $this->connection->cd($origin);
             continue;
         }
         if (!($tmpFiles = $this->connection->ls())) {
             $this->output(" - Nothing to purge in {$dir}");
             $this->connection->cd($origin);
             continue;
         }
         $haveFiles = false;
         $innerDirs = array();
         foreach ($tmpFiles as $file) {
             $curr = $this->connection->pwd();
             if ($this->connection->cd($file)) {
                 $innerDirs[] = $file;
                 $this->connection->cd($curr);
             } else {
                 $haveFiles = true;
                 $this->output(" - {$file} is removed from directory");
                 $this->connection->rm($file);
             }
         }
         if (!$haveFiles) {
             $this->output(" - Nothing to purge in {$dir}");
         } else {
             $this->output("<red>Purged <white>{$dir}");
         }
         if (count($innerDirs) > 0) {
             // Recursive purging
             $this->purge($innerDirs);
         }
         $this->connection->cd($origin);
     }
 }
Exemple #3
0
 /**
  * Purge given directory's contents
  *
  * @var string $purgeDirs
  */
 public function purge($purgeDirs)
 {
     foreach ($purgeDirs as $dir) {
         $origin = $this->connection->pwd();
         $this->connection->cd($dir);
         $this->output("<red>Purging directory <white>{$dir}");
         if (!($tmpFiles = $this->connection->ls())) {
             $this->output(" - Nothing to purge in {$dir}");
             $this->connection->cd($origin);
             continue;
         }
         $haveFiles = false;
         $innerDirs = [];
         foreach ($tmpFiles as $file) {
             $curr = $this->connection->pwd();
             if ($this->connection->cd($file)) {
                 $innerDirs[] = $file;
                 $this->connection->cd($curr);
             } else {
                 $haveFiles = true;
                 $this->output(" - {$file} is removed from directory");
                 $this->connection->rm($file);
             }
         }
         if (!$haveFiles) {
             $this->output(" - Nothing to purge in {$dir}");
         } else {
             $this->output("<red>Purged <white>{$dir}");
         }
         if (count($innerDirs) > 0) {
             $this->purge($innerDirs);
         }
         $this->connection->cd($origin);
     }
 }
Exemple #4
0
 /**
  * Purge given directory's contents
  *
  * @var string $purgeDirs
  */
 public function purge($purgeDirs)
 {
     foreach ($purgeDirs as $dir) {
         $origin = $this->connection->pwd();
         $this->connection->cd($dir);
         if (!($tmpFiles = $this->connection->ls())) {
             $this->output("Nothing to purge in {$dir}");
             continue;
         }
         $this->output("<red>Purging <white> ...");
         foreach ($tmpFiles as $file) {
             $this->connection->rm($file);
         }
         $this->output("<red>Purged <white>{$dir}");
         $this->connection->cd($origin);
     }
 }