public function getRemoteFile($url) { $fg = RemoteFileGetterFactory::getFGInstance(); if ($this->getParam("CSV:remoteauth", false) == true) { $user = $this->getParam("CSV:remoteuser"); $pass = $this->getParam("CSV:remotepass"); $fg->setCredentials($user, $pass); } $cookies = $this->getParam("CSV:remotecookie"); if ($cookies) { $fg->setCookie($cookies); } $this->log("Fetching CSV: {$url}", "startup"); // output filename (current dir+remote filename) $csvdldir = dirname(__FILE__) . "/downloads"; if (!file_exists($csvdldir)) { @mkdir($csvdldir); @chmod($csvdldir, Magmi_Config::getInstance()->getDirMask()); } $outname = $csvdldir . "/" . basename($url); $ext = substr(strrchr($outname, '.'), 1); if ($ext != "txt" && $ext != "csv") { $outname = $outname . ".csv"; } // open file for writing if (file_exists($outname)) { if ($this->getParam("CSV:forcedl", false) == true) { unlink($outname); } else { return $outname; } } $fg->copyRemoteFile($url, $outname); // return the csv filename return $outname; }
/** * Download a file into local filesystem * ensures local filename will be located under magento directory if not already * * @param unknown $remoteurl * @param unknown $destpath * @return unknown */ public function copyFromRemote($remoteurl, $destpath) { $rfg = RemoteFileGetterFactory::getFGInstance($this->_rfgid); $mp = str_replace("//", "/", $this->_magdir . "/" . str_replace($this->_magdir, '', $destpath)); $ok = $rfg->copyRemoteFile($remoteurl, $mp); if (!$ok) { $this->_lasterror = $rfg->getErrors(); } return $ok; }