Пример #1
0
 /**
  * ftpMoveFiles
  * 
  * @param string $from
  * @param string $to
  * @param int    $chmodf
  * @param int    $chmodd
  * @param bool   $overwrite
  */
 public function ftpMoveFiles($from = '', $to = '', $chmodf = 0644, $chmodd = 0755, $overwrite = false)
 {
     foreach (self::$_instance->iterator($from) as $f) {
         if (self::$_instance->is_dir($from . '/' . $f)) {
             self::$_instance->mkdir($to . '/' . $f, $chmodd);
             $this->ftpMoveFiles($from . '/' . $f, $to . '/' . $f, $chmodf, $chmodd, $overwrite);
         } else {
             if ($overwrite || !self::$_instance->file_exists($to . '/' . $f)) {
                 self::$_instance->file_put_contents($to . '/' . $f, self::$_instance->file_get_contents($from . '/' . $f));
                 $this->rechmod($to . '/' . $f, $chmodf);
             }
             self::$_instance->unlink($from . '/' . $f);
         }
     }
     self::$_instance->rmdir($from);
 }
Пример #2
0
 /**
  * Quick remove method for a single folder.
  *
  * @param string $strFolder
  * @param array $ftpSettings (host, username, password)
  * @param boolean $blnSecure
  * @throws \RuntimeException
  */
 public static function ftpRemoveDir($strFolder, $ftpSettings, $blnSecure = false)
 {
     $objFtp = new FTP($ftpSettings['host'], 21, 90, $blnSecure);
     $objRet = $objFtp->login($ftpSettings['username'], $ftpSettings['password']);
     if (!$objRet) {
         throw new \RuntimeException("Could not login to FTP server.", 404);
     }
     //*** Passive mode.
     $objFtp->pasv(true);
     //*** Remove the file.
     try {
         //*** Check if the folder is empty.
         $arrFiles = $objFtp->nlist($strFolder);
         if ($arrFiles !== false && count($arrFiles) == 0) {
             @$objFtp->rmdir($strFolder);
         }
     } catch (\Exception $ex) {
         //*** Ignore. Probably already removed.
     }
 }