Ejemplo n.º 1
0
 /**
  * Publish the specified feed file.
  *
  * @param string $filepath
  * @param array $params
  * @return Grommet_ProductFeed_Model_Feed_Publisher_Ftp
  */
 public function publish($filepath, array $params = array())
 {
     if (empty($params['host']) || empty($params['user']) || empty($params['password'])) {
         throw new Mage_Core_Exception('Invalid FTP parameters - host, user and password must be set.');
     }
     $ftp = new Varien_Io_Ftp();
     $ftp->open($params);
     $filename = pathinfo($filepath, PATHINFO_BASENAME);
     $writeResult = $ftp->write($filename, $filepath);
     if (!$writeResult) {
         throw new Mage_Core_Exception('Unable to write file ' . $filename . ' to FTP.');
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Upload file by file map to Google FTP server and delete it from local file system
  *
  * @param array $fileNameMap   array(array('local' => 'local file name', 'remote' => 'remote file name'), ...)
  * @param mixed $store
  *
  * @throws Varien_Io_Exception If FTP related error occurred
  */
 protected function _uploadFiles(array &$fileNameMap, $store)
 {
     $ftp = new Varien_Io_Ftp();
     $fs = new Varien_Io_File();
     try {
         $ftp->open(array('host' => $host = $this->_getConfig()->getFtpHostName(), 'user' => $this->_getConfig()->getFtpUserName($store), 'password' => $this->_getConfig()->getFtpPassword($store), 'passive' => $this->_getConfig()->getFtpMode($store)));
     } catch (Exception $e) {
         foreach ($fileNameMap as &$item) {
             $item['error_message'] = $e->getMessage();
         }
         throw $e;
     }
     $uploadedFiles = array();
     $exceptions = array();
     foreach ($fileNameMap as &$item) {
         if ($fs->fileExists($item['local'])) {
             $result = $ftp->write($item['remote'], $item['local']);
             if (false === $result) {
                 $item['error_message'] = Mage::helper('googletrustedstore')->__("Unable to upload '%s' to '%s' on server %s", $item['local'], $item['remote'], $host);
                 $exceptions[] = $item['error_message'];
             } else {
                 $uploadedFiles[] = $item['local'];
                 $fs->rm($item['local']);
                 $item['successfully'] = true;
             }
         } else {
             $item['error_message'] = Mage::helper('googletrustedstore')->__("The '%s' file does not exist on Magento server", $item['local']);
         }
     }
     $ftp->close();
     if (!empty($exceptions)) {
         throw new Varien_Io_Exception(implode(PHP_EOL, $exceptions));
     }
     return $uploadedFiles;
 }
Ejemplo n.º 3
0
 public function ftpAction()
 {
     $ftpHost = $this->getRequest()->getParam('ftp_host');
     $ftpLogin = $this->getRequest()->getParam('ftp_login');
     $ftpPassword = $this->getRequest()->getParam('ftp_password');
     $ftpDir = $this->getRequest()->getParam('ftp_dir');
     $useSftp = $this->getRequest()->getParam('use_sftp');
     $ftpActive = $this->getRequest()->getParam('ftp_active');
     if ($useSftp) {
         $ftp = new Varien_Io_Sftp();
     } else {
         $ftp = new Varien_Io_Ftp();
     }
     try {
         $ftp->open(array('host' => $ftpHost, 'user' => $ftpLogin, 'username' => $ftpLogin, 'password' => $ftpPassword, 'timeout' => '120', 'path' => $ftpDir, 'passive' => !$ftpActive));
         $ftp->write(null, null);
         $ftp->close();
         die("Connection succeeded");
     } catch (Exception $e) {
         die(Mage::helper("massstockupdate")->__("Ftp error : ") . $e->getMessage());
     }
 }
Ejemplo n.º 4
0
 /**
  * Upload Feed to FTP server if required.
  */
 protected function _sendFeed()
 {
     if (Mage::getStoreConfigFlag(self::CONFIG_FTP_ENABLED)) {
         $oFtp = new Varien_Io_Ftp();
         $bSuccess = $oFtp->open(array('host' => Mage::getStoreConfig(self::CONFIG_FTP_HOST), 'user' => Mage::getStoreConfig(self::CONFIG_FTP_USER), 'password' => Mage::getStoreConfig(self::CONFIG_FTP_PASS)));
         if (!$bSuccess) {
             Mage::getSingleton('aligent_feeds/log')->log("Unable to connect to FTP Server");
             Mage::getSingleton('aligent_feeds/status')->addError("", "Unable to connect to FTP Server");
             return;
         }
         $bSuccess = $oFtp->cd(Mage::getStoreConfig(self::CONFIG_FTP_PATH));
         if (!$bSuccess) {
             Mage::getSingleton('aligent_feeds/log')->log("Unable change directories on FTP Server");
             Mage::getSingleton('aligent_feeds/status')->addError("", "Unable to connect to FTP Server");
             return;
         }
         foreach ($this->_oWriters as $oWriter) {
             $vFilename = $oWriter->getFilename();
             $bSuccess = $oFtp->write(basename($vFilename), $vFilename);
             if (!$bSuccess) {
                 Mage::getSingleton('aligent_feeds/log')->log("Unable to upload {$vFilename} to FTP server");
                 Mage::getSingleton('aligent_feeds/status')->addError("", "Unable to upload {$vFilename} to FTP server");
                 return;
             }
         }
         $oFtp->close();
     }
 }
Ejemplo n.º 5
0
 /**
  * Upload file by file map to Google FTP server and delete it from local file system
  *
  * @param array $fileNameMap   array('local file name' => 'remote file name', ...)
  * @param mixed $store
  *
  * @throws Varien_Io_Exception If FTP related error occurred
  */
 protected function _uploadFiles(array $fileNameMap, $store)
 {
     $ftp = new Varien_Io_Ftp();
     $fs = new Varien_Io_File();
     $result = $ftp->open(array('host' => $host = $this->_getConfig()->getFtpHostName(), 'user' => $this->_getConfig()->getFtpUserName($store), 'password' => $this->_getConfig()->getFtpPassword($store), 'passive' => $this->_getConfig()->getFtpMode($store)));
     $uploadedFiles = array();
     foreach ($fileNameMap as $localFileName => $targetFileName) {
         if ($fs->fileExists($localFileName)) {
             $uploadedFiles[] = $localFileName;
             $result = $ftp->write($targetFileName, $localFileName);
             if (false === $result) {
                 throw new Varien_Io_Exception(Mage::helper('googletrustedstore')->__("Unable to upload '%s' to '%s' on server %s", $localFileName, $targetFileName, $host));
             }
             $fs->rm($localFileName);
         }
     }
     $ftp->close();
     return $uploadedFiles;
 }
Ejemplo n.º 6
0
 public function uploadToFtp()
 {
     if ($this->getActivateFtp() == 1) {
         $hostPort = explode(':', $this->getFtpHostPort());
         if (empty($hostPort[0])) {
             return;
         }
         if (empty($hostPort[1])) {
             $hostPort[1] = 21;
         }
         $args = array('host' => trim($hostPort[0]), 'port' => trim($hostPort[1]), 'user' => $this->getFtpUser(), 'password' => $this->getFtpPassword(), 'passive' => true, 'path' => $this->getFtpPath(), 'timeout' => 5);
         $exportFile = $this->_getExportPath($this) . DS . $this->getFilename();
         try {
             $ftp = new Varien_Io_Ftp();
             $ftp->open($args);
             $ftp->write($this->getFilename(), $exportFile);
             $ftp->close();
         } catch (Varien_Io_Exception $e) {
             echo $e->getMessage();
         }
     }
 }