Exemplo n.º 1
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.
     }
 }