Ejemplo n.º 1
0
 protected function sendDataSftp()
 {
     $directory = new \Bitrix\Main\IO\Directory($this->path . "/zip");
     if (!$directory->isExists()) {
         throw new SystemException("Directory" . $this->path . "/zip does not exist! " . __METHOD__);
     }
     $filesToSend = $directory->getChildren();
     if (empty($filesToSend)) {
         return false;
     }
     $sftp = \Bitrix\Sale\TradingPlatform\Ebay\Helper::getSftp($this->siteId);
     $sftp->connect();
     for ($i = 0; $i < count($filesToSend); $i++) {
         $directoryEntry = $filesToSend[$i];
         $localPath = $directoryEntry->getPath();
         if (!$directoryEntry instanceof \Bitrix\Main\IO\File || GetFileExtension($localPath) != "zip") {
             continue;
         }
         $remote = $this->remotePath . "/" . $directoryEntry->getName();
         while (!$this->checkOuterConditions($sftp)) {
             if ($this->timer !== null && !$this->timer->check(15)) {
                 return false;
             }
             sleep(10);
         }
         if ($sftp->uploadFile($localPath, $remote)) {
             $directoryEntry->delete();
             ResultsTable::add(array("FILENAME" => $directoryEntry->getName(), "FEED_TYPE" => $this->feedType, "UPLOAD_TIME" => DateTime::createFromTimestamp(time())));
             Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_SFTPQUEUE_SEND", $remote, "File sent successfully.", $this->siteId);
         }
     }
     return true;
 }