Exemple #1
0
 public function moveToFTP($strLocalName, $strUploadFolder, $strServer, $strUsername, $strPassword, $strRemoteFolder)
 {
     $blnReturn = true;
     if (!empty($strLocalName)) {
         //*** Connect to the server.
         $objFtp = new FTP($strServer, NULL, NULL, TRUE);
         $objRet = $objFtp->login($strUsername, $strPassword);
         if (!$objRet) {
             $this->arrMessages[] = "Login failed. Check credentials.";
             $blnReturn = false;
         }
         //*** Passive mode.
         $objFtp->pasv(TRUE);
         //*** Transfer file.
         $objRet = $objFtp->nb_put($strRemoteFolder . $strLocalName, $strUploadFolder . $strLocalName, FTP_BINARY);
         while ($objRet == FTP_MOREDATA) {
             // Continue uploading...
             $objRet = $objFtp->nb_continue();
         }
         if ($objRet != FTP_FINISHED) {
             //*** Something went wrong.
             $this->arrMessages[] = $this->getErrorMessage($this->intHttpError);
             $blnReturn = false;
         }
         //*** Remove local file.
         @unlink($strUploadFolder . $strLocalName);
     }
     return $blnReturn;
 }
Exemple #2
0
 /**
  * Quick upload mthod for a single file.
  *
  * @param string $sourceFile local file name
  * @param array $ftpSettings (path.uploads, host, username, password)
  * @throws \RuntimeException
  */
 public static function ftpUpload($sourceFile, $ftpSettings, $targetFile = null, $blnSecure = false)
 {
     $strFtpFileName = is_null($targetFile) ? basename($sourceFile) : $targetFile;
     $strFtpFileDir = $ftpSettings['path']['uploads'];
     $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);
     //*** Create dealer folder.
     try {
         $objFtp->mksubdirs($strFtpFileDir);
     } catch (\Exception $ex) {
         //*** Ignore. The folder probably already exists.
     }
     //*** Transfer file.
     $objRet = $objFtp->nb_put($strFtpFileName, $sourceFile, FTP_BINARY);
     while ($objRet == FTP_MOREDATA) {
         // Continue uploading...
         $objRet = $objFtp->nb_continue();
     }
     if ($objRet != FTP_FINISHED) {
         //*** Something went wrong.
         throw new \RuntimeException("FTP transfer of {$strFtpFileName} interruppted.", 500);
     }
     //*** Remove local file.
     if (file_exists($sourceFile)) {
         @unlink($sourceFile);
     }
 }
Exemple #3
0
 public static function moveImportedFiles($objAccount)
 {
     global $_CONF, $_PATHS;
     $sourceDir = $_PATHS['upload'] . $objAccount->getId() . "/";
     if (is_dir($sourceDir)) {
         $strServer = Setting::getValueByName('ftp_server', $objAccount->getId());
         $strUsername = Setting::getValueByName('ftp_username', $objAccount->getId());
         $strPassword = Setting::getValueByName('ftp_password', $objAccount->getId());
         $strRemoteFolder = Setting::getValueByName('ftp_remote_folder', $objAccount->getId());
         //*** Try to move the files.
         $objFtp = new FTP($strServer, NULL, NULL, true);
         if ($objFtp->login($strUsername, $strPassword) === true) {
             //*** Passive mode.
             $objFtp->pasv(true);
             if ($objHandle = opendir($sourceDir)) {
                 while (false !== ($strFile = readdir($objHandle))) {
                     if ($strFile != "." && $strFile != "..") {
                         //*** Transfer file.
                         $objRet = $objFtp->nb_put($strRemoteFolder . $strFile, $sourceDir . $strFile, FTP_BINARY);
                         while ($objRet == FTP_MOREDATA) {
                             // Continue uploading...
                             $objRet = $objFtp->nb_continue();
                         }
                         if ($objRet != FTP_FINISHED) {
                             //*** Something went wrong. Continue without error.
                         } else {
                             //*** Remove local file.
                             @unlink($sourceDir . $strFile);
                         }
                     }
                 }
                 closedir($objHandle);
             }
         }
         //*** Remove dir if empty.
         if (count(scandir($sourceDir)) <= 2) {
             rmdir($sourceDir);
         }
     }
 }