Exemple #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();
 }
Exemple #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;
 }
Exemple #3
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();
     }
 }
Exemple #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();
     }
 }
Exemple #5
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();
     }
 }
Exemple #6
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;
 }
Exemple #7
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();
         }
     }
 }