Example #1
0
 public function download(Varien_Object $connectionInfo, $target)
 {
     $file = $connectionInfo->getFile();
     $this->_log($this->_getLog()->__("Connecting to FTP server %s", $connectionInfo->getHost()));
     $ftp = new Varien_Io_Ftp();
     $ftp->open(array('host' => $connectionInfo->getHost(), 'user' => $connectionInfo->getUsername(), 'password' => $connectionInfo->getPassword(), 'timeout' => $connectionInfo->hasTimeout() ? $connectionInfo->getTimeout() : 10, 'passive' => $connectionInfo->hasPassive() ? $connectionInfo->getPassive() : true, 'ssl' => $connectionInfo->hasSsl() ? $connectionInfo->getSsl() : null, 'file_mode' => $connectionInfo->hasFileMode() ? $connectionInfo->getFileMode() : null));
     if (!is_writable(Mage::getBaseDir() . DS . $target)) {
         Mage::throwException($this->_getLog()->__("Can not write file %s to %s, folder not writable (doesn't exist?)", $connectionInfo->getFile(), $target));
     }
     $this->_log($this->_getLog()->__("Downloading file %s from %s, to %s", $connectionInfo->getFile(), $connectionInfo->getHost(), $target));
     $targetPath = $this->_getTargetPath($target, basename($file));
     $ftp->read($file, $targetPath);
     $ftp->close();
 }
Example #2
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;
 }
Example #3
0
 public function connect(array $config = array())
 {
     $ftp = new Varien_Io_Ftp();
     if (empty($config)) {
         $config['host'] = $this->getConfigValue(self::HOST);
         $config['port'] = (int) $this->getConfigValue(self::PORT);
         $config['user'] = $this->getConfigValue(self::USERNAME);
         $config['password'] = $this->getConfigValue(self::PASSWORD);
         $config['timeout'] = $this->getTimeOut();
         $config['ssl'] = $this->getConfigValue(self::SSL);
         $config['passive'] = $this->getConfigValue(self::PASSIVE);
         $config['path'] = $this->getConfigValue(self::PATH);
     }
     try {
         $ftp->open($config);
     } catch (Exception $e) {
         Mage::logException($e);
         $this->_throwExeption($e->getMessage());
     }
     $this->setFtp($ftp);
     return $this;
 }
Example #4
0
 /**
  * Download Images (Step 6)
  *
  * @param Pimgento_Core_Model_Task $task
  *
  * @return bool
  */
 public function downloadImages($task)
 {
     $adapter = $this->getAdapter();
     $ftp = null;
     try {
         $connexion = Mage::getStoreConfig('pimdata/asset/connexion');
         if ($connexion == 'ftp') {
             /* @var $ftp Varien_Io_Ftp */
             $ftp = new Varien_Io_Ftp();
             $config = array('host' => Mage::getStoreConfig('pimdata/asset/host'), 'user' => Mage::getStoreConfig('pimdata/asset/user'), 'password' => Mage::getStoreConfig('pimdata/asset/password'));
             if (Mage::getStoreConfig('pimdata/asset/directory')) {
                 $config['path'] = Mage::getStoreConfig('pimdata/asset/directory');
             }
             if (Mage::getStoreConfig('pimdata/asset/passive')) {
                 $config['passive'] = true;
             }
             $ftp->open($config);
         } else {
             if ($connexion == 'sftp') {
                 /* @var $ftp Varien_Io_Sftp */
                 $ftp = new Varien_Io_Sftp();
                 $config = array('host' => Mage::getStoreConfig('pimdata/asset/host'), 'username' => Mage::getStoreConfig('pimdata/asset/user'), 'password' => Mage::getStoreConfig('pimdata/asset/password'));
                 $ftp->open($config);
                 if (Mage::getStoreConfig('pimdata/asset/directory')) {
                     $ftp->cd(Mage::getStoreConfig('pimdata/asset/directory'));
                 }
             } else {
                 $task->error(Mage::helper('pimgento_asset')->__('Connexion type %s is not authorised', $connexion));
             }
         }
         if ($ftp) {
             $select = $adapter->select()->from($adapter->getTableName('pimgento_asset'), array('file', 'image'));
             $query = $adapter->query($select);
             $directory = Mage::helper('pimgento_asset')->getBaseMediaPath();
             while ($row = $query->fetch()) {
                 $dir = dirname($directory . $row['image']);
                 if (!is_dir($dir)) {
                     mkdir($dir, 0777, true);
                 }
                 $ftp->read($row['file'], $directory . $row['image']);
             }
             $ftp->close();
         }
     } catch (Exception $e) {
         $task->error(Mage::helper('pimgento_asset')->__($e->getMessage()));
     }
     return true;
 }
Example #5
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;
 }
Example #6
0
 private function downloadFile()
 {
     $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));
         if ($ftp->cd($ftpDir)) {
             $filename = 'var/tmp/stock_import_' . time() . '.csv';
             $io = new Varien_Io_File();
             $realPath = $io->getCleanPath(Mage::getBaseDir() . '/var/tmp/');
             if (is_readable($realPath)) {
                 $content = $ftp->read($this->getRequest()->getParam('file_path'), $filename);
                 $ftp->close();
                 if (!$content) {
                     return array("The file '" . $this->getRequest()->getParam('file_path') . "' cannot be fetched.");
                 }
                 return $filename;
             } else {
                 $ftp->close();
                 return array("Please make sure that var/tmp is writable.");
             }
         } else {
             $ftp->close();
             return array("Cannot access '{$ftpDir}' on this server.");
         }
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Example #7
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();
     }
 }
Example #8
0
 private function x91()
 {
     $x7a = "stristr";
     $x7b = "is_readable";
     $x7c = "time";
     $x7d = "file_get_contents";
     $x7e = "in_array";
     $x7f = "implode";
     $x80 = "array_key_exists";
     $x81 = "trim";
     $x82 = "str_replace";
     $x83 = "log";
     $x84 = "is_array";
     $x85 = "json_encode";
     $x86 = "json_decode";
     $x87 = "array_splice";
     $x88 = "array_unshift";
     $x89 = "count";
     $x8a = "is_numeric";
     $x8b = "array_push";
     $x8c = "strtolower";
     $x8d = "strstr";
     $x8e = "explode";
     $x8f = "addslashes";
     $x33 = $this->getFtpHost();
     $x34 = $this->getFtpLogin();
     $x35 = $this->getFtpPassword();
     $x36 = $this->getFtpDir();
     $x37 = $this->getUseSftp();
     $x38 = $this->getFtpActive();
     if ($x37) {
         $x39 = new Varien_Io_Sftp();
     } else {
         $x39 = new Varien_Io_Ftp();
     }
     try {
         $x39->open(array('host' => $x33, 'user' => $x34, 'username' => $x34, 'password' => $x35, 'timeout' => '120', 'path' => $x36, 'passive' => !$x38));
         if ($x39->cd($x36)) {
             $x3a = 'var/tmp/stock_import_' . $x7c() . '.csv';
             $x31 = new Varien_Io_File();
             $x32 = $x31->getCleanPath(Mage::getBaseDir() . '/var/tmp/');
             if ($x7b($x32)) {
                 $x3b = $x39->read($this->getFilePath(), $x3a);
                 $x39->close();
                 if (!$x3b) {
                     return array("The file '" . $this->getFilePath() . "' cannot be fetched.");
                 }
                 return $x3a;
             } else {
                 $x39->close();
                 return array("Please make sure that var/tmp is writable.");
             }
         } else {
             $x39->close();
             return array("Cannot access '{$x36}' on this server.");
         }
     } catch (Exception $x3c) {
         return $x3c->getMessage();
     }
 }
Example #9
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;
 }
Example #10
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();
         }
     }
 }
Example #11
0
 public function filteredLs()
 {
     $result = parent::ls();
     return Mage::getSingleton('udbatch/io')->filterLs($result, $this);
 }