public function downloadFile() { $requestURL = trim(Mage::getStoreConfig('pulliver/western_power/base_url'), ' /'); $username = Mage::getStoreConfig('pulliver/western_power/username'); $password = Mage::getStoreConfig('pulliver/western_power/password'); $connection = ftp_connect($requestURL); if (!$connection) { Vikont_Pulliver_Helper_Data::inform(sprintf('Could not connect to %s', $requestURL)); } if (!@ftp_login($connection, $username, $password)) { Vikont_Pulliver_Helper_Data::throwException(sprintf('Error logging to FTP %s as %s', $requestURL, $username)); } $remoteFileName = Mage::getStoreConfig('pulliver/western_power/remote_filename'); $localFileName = $this->getLocalFileName($remoteFileName, 'downloaded/'); if (file_exists($localFileName)) { @unlink($localFileName); } else { if (!file_exists($dirName = dirname($localFileName))) { mkdir($dirName, 0777, true); } } Vikont_Pulliver_Helper_Data::type("Downloading {$requestURL}/{$remoteFileName}..."); $startedAt = time(); if (!ftp_get($connection, $localFileName, $remoteFileName, FTP_BINARY)) { Vikont_Pulliver_Helper_Data::throwException(sprintf('Error downloading from FTP %s/%s to %s', $requestURL, $remoteFileName, $localFileName)); } ftp_close($connection); $timeTaken = time() - $startedAt; Vikont_Pulliver_Helper_Data::inform(sprintf('Inventory successfully downloaded from %s/%s to %s, size=%dbytes, time=%ds', $requestURL, $remoteFileName, $localFileName, filesize($localFileName), $timeTaken)); return $localFileName; }
/** * Function that retrieves a file from FTP library and compress it if necessary * * @param string $file File name to be retrieved from FTP library * @return boolean */ public function get_file($file, $dir = '') { if (!defined("LOCATION") || !defined("CODE") || !defined("LIBRARY") || !defined("CACHE_PATH")) { $this->container->__error("Imposible recuperar el archivo remoto: falta alguna constante por definir"); return false; } $cnn = ftp_connect(LOCATION); $rs = ftp_login($cnn, LIBRARY, CODE); if ($rs === false) { $this->container->__error("Imposible conectar a la libreria de funciones!"); } $dir = $dir == '' ? '' : $dir . DIRECTORY_SEPARATOR; ftp_chdir($cnn, LIBRARY . DIRECTORY_SEPARATOR . $dir); if (@ftp_chdir($cnn, $file) !== false) { if ($this->container->__debug()) { @mkdir(CACHE_PATH . $dir . $file); chmod(CACHE_PATH . $dir . $file, 0777); $dir = $dir == '' ? $file : $dir . $file; } else { @mkdir(CACHE_PATH . $dir . md5($file)); chmod(CACHE_PATH . $dir . md5($file), 0777); $dir = $dir == '' ? $file : $dir . $file; } $files = ftp_nlist($cnn, "."); foreach ($files as $filea) { $this->get_file($filea, $dir); } return true; } else { if ($file == '.' || $file == '..') { return; } if ($this->container->__debug()) { $aux = ftp_get($cnn, CACHE_PATH . $dir . $file, $file, FTP_BINARY); } else { $temp = explode(DIRECTORY_SEPARATOR, $dir); array_walk($temp, function (&$element, $index) { $element = md5($element); }); array_pop($temp); $temp = implode(DIRECTORY_SEPARATOR, $temp) . DIRECTORY_SEPARATOR; $aux = ftp_get($cnn, CACHE_PATH . $temp . md5($file), $file, FTP_BINARY); } if (!$aux) { ftp_close($cnn); $this->container->__error("Imposible obtener el archivo para cache: " . $file); return false; } else { ftp_close($cnn); if ($this->container->__debug()) { chmod(CACHE_PATH . $dir . $file, 0777); $this->compress_cache_file($dir . $file); } else { chmod(CACHE_PATH . $temp . md5($file), 0777); $this->compress_cache_file($temp . md5($file)); } return true; } } }
function GetMD5() { global $ftp; global $dir; global $remote_file; $md5 = null; $checksum_file = str_replace('.installer.exe', '.checksums', $remote_file); $local_checksums = 'nightly-checksums.dat'; if (is_file($local_checksums)) { unlink($local_checksums); } if (ftp_get($ftp, $local_checksums, "{$dir}{$checksum_file}", FTP_ASCII)) { $checksums = file($local_checksums); if ($checksums && is_array($checksums)) { foreach ($checksums as $line) { if (strstr($line, $remote_file) !== FALSE) { list($hash, $type, $size, $file) = explode(' ', trim($line)); if ($type == 'md5') { $md5 = $hash; break; } } } } } if (is_file($local_checksums)) { unlink($local_checksums); } return $md5; }
public function actionSynchronization() { if (date('w', time()) == 0 || date('w', time()) == 6) { return; } $transfer_src = ftp_connect('91.197.79.112'); $login_result = ftp_login($transfer_src, 'transfer', 'dnUtd74n'); if (!$login_result) { return false; } ftp_pasv($transfer_src, TRUE); $files = ftp_nlist($transfer_src, "."); foreach ($files as $file) { if (!is_file(Yii::getAlias('@backend/web/') . $this->upload_dir . '/' . $file)) { $transfer_dst = ftp_connect('37.46.85.148'); $login_result = ftp_login($transfer_dst, 'carakas', 'hokwEw21'); if (!$login_result) { return false; } ftp_pasv($transfer_dst, TRUE); ftp_get($transfer_src, Yii::getAlias('@backend/web/') . $this->upload_dir . '/' . $file, $file, FTP_ASCII); ftp_put($transfer_dst, $file, Yii::getAlias('@backend/web/') . $this->upload_dir . '/' . $file, FTP_BINARY); ftp_close($transfer_dst); } } ftp_close($transfer_src); }
private function lista_detallada($resource, $directorio = '.') { if (is_array($children = @ftp_rawlist($resource, $directorio))) { $items = array(); foreach ($children as $child) { $chunks = preg_split("/\\s+/", $child); list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks; $item['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file'; array_splice($chunks, 0, 8); $items[implode(" ", $chunks)] = $item; //$chunks contiene el nombre del archivo //echo "\n chunks---------------------------------\n"; //print_r($chunks); //echo "\n"; // descargo archivo si tiene extension txt if (substr($chunks[0], -4) == ".txt") { $local_file = "temp/" . $chunks[0]; $server_file = $chunks[0]; if (!file_exists($local_file)) { //si el archivo no existe lo descargo if (ftp_get($resource, $local_file, $server_file, FTP_ASCII)) { echo "Se descargo archivo\n"; } else { echo "ERROR! No se pudo descargar archivo\n"; } } } } return $items; } return false; }
/** * @inheritdoc */ public function get($localFile, $remoteFile, $mode = FTP_ASCII) { if (false === ftp_get($this->getFtp(), $localFile, $remoteFile, $mode)) { throw new \Exception("Unable to get file:" . $remoteFile); } return true; }
function get($local, $remote, $mode = null) { if ($mode === null) { $mode = FTP_BINARY; } return ftp_get($this->res, $local, $remote, $mode); }
function ftp_sync($dir) { global $conn_id; if ($dir != ".") { if (ftp_chdir($conn_id, $dir) == false) { echo "Change Dir Failed: {$dir}<BR>\r\n"; return; } if (!is_dir($dir)) { mkdir($dir); } chdir($dir); } $contents = ftp_nlist($conn_id, "."); foreach ($contents as $file) { if ($file == '.' || $file == '..') { continue; } if (@ftp_chdir($conn_id, $file)) { ftp_chdir($conn_id, ".."); ftp_sync($file); } else { ftp_get($conn_id, $file, $file, FTP_BINARY); } } ftp_chdir($conn_id, ".."); chdir(".."); }
public function download(string $remotePath, string $localPath, string $type = 'ascii') : bool { if (ftp_get($this->connect, $localPath, $remotePath, Converter::toConstant($type, 'FTP_'))) { return true; } else { throw new FileRemoteDownloadException($localPath); } }
/** * Downloads a remote file * @link http://php.net/ftp_get * * @param string $localFile The local file path * @param string $remoteFile The remote file path * @param integer $mode The transfer mode (FTPWrapper::ASCII, FTPWrapper::BINARY) * @param integer $resumepos The position in the remote file to start downloading from * @return boolean TRUE on success, FALSE on failure */ public function get($localFile, $remoteFile, $mode = self::BINARY, $resumepos = 0) { try { return ftp_get($this->connection->getStream(), $localFile, $remoteFile, $mode, $resumepos); } catch (\Exception $e) { return ftp_get($this->connection->getStream(), $localFile, str_replace(' ', '\\ ', $remoteFile), $mode, $resumepos); } }
/** * Downloads file * * @param string $localName Path to save the file * @param int $mode The transfer mode, <code>FTP_ASCII</code> or <code>FTP_BINARY</code> * @param int $startPos The position in the remote file to start downloading from * @throws cFTP_Exception * * @return cFTP_File This */ public function download($localName, $mode = FTP_BINARY, $startPos = 0) { $success = @ftp_get( $this->handle, $localName, $this->name, $mode, $startPos ); if( !$success ) throw new cFTP_Exception( "Could not download file", 30 ); return $this; }
public function download($file, $path, $mode = FTP_BINARY) { if (isset($file)) { if (ftp_get($this->ftpcon, $path, $file, FTP_BINARY)) { return true; } } return false; }
function bajar_r($from, $to, $retries = 1) { $tries = 0; $bajado = false; while (!$bajado && $tries < $retries) { $bajado = ftp_get($this->id_conn, $to, $from, FTP_BINARY); $tries++; } return $bajado; }
/** * 方法:复制文件 * 说明:由于FTP无复制命令,本方法变通操作为:下载后再上传到新的路径 * @path -- 原路径 * @newpath -- 新路径 * @type -- 若目标目录不存在则新建 */ function copy_file($path, $newpath, $type = true) { $downpath = "c:/tmp.dat"; $this->off = @ftp_get($this->conn_id, $downpath, $path, FTP_BINARY); // 下载 if (!$this->off) { echo "文件复制失败,请检查权限及原路径是否正确!"; } $this->up_file($downpath, $newpath, $type); }
/** * 方法:复制文件 * 说明:由于FTP无复制命令,本方法变通操作为:下载后再上传到新的路径 * @path -- 原路径 * @newpath -- 新路径 * @type -- 若目标目录不存在则新建 */ function copy_file($path, $newpath, $type = true) { $downpath = "c:/tmp.dat"; $this->off = @ftp_get($this->conn_id, $downpath, $path, FTP_BINARY); // 下载 if (!$this->off) { return false; } else { return $this->up_file($downpath, $newpath, $type); } }
public function getBouquets($folderName) { // TODO delete old files $files = ftp_nlist($this->_ftpStream, '/etc/enigma2/'); foreach ($files as $fn) { if (pathinfo($fn, PATHINFO_EXTENSION) == 'tv') { $target = $folderName . DIRECTORY_SEPARATOR . pathinfo($fn, PATHINFO_BASENAME); ftp_get($this->_ftpStream, $target, $fn, FTP_ASCII); } } }
public function read($dest) { $tempFile = tempnam(sys_get_temp_dir(), ''); $destFullPath = $this->getOption('path') . $dest; if (false === ftp_get($this->_getConnection(), $tempFile, $destFullPath, FTP_BINARY)) { return false; } $str = file_get_contents($tempFile); unlink($tempFile); return $str; }
function get_contents($file) { if ($ftp = AkFtpClient::connect()) { $file = str_replace('\\', '/', $file); $tmpfname = tempnam('/tmp', 'tmp'); ftp_get($ftp, $tmpfname, $file, FTP_BINARY); $file_contents = @file_get_contents($tmpfname); unlink($tmpfname); return $file_contents; } }
function get_file($local, $remote) { global $strErrFtpNoGet; @ftp_pasv($this->ftpc, true); $download = @ftp_get($this->ftpc, $local, $remote, FTP_BINARY); if (!$download) { AA_printErrorMsg($strErrFtpNoGet); return false; } else { return true; } }
public function nobget($local,$remote) { if(!$this->connid) { $this->errorid = 2; return false; } if(@ftp_get($this->connid,$local,$remote,$this->connmode)) { return true; }else { $this->errorid = 8; return false; } }
/** * {@inheritdoc} */ public function allocateFilename(BucketInterface $bucket, $name) { if (!$this->exists($bucket, $name)) { throw new ServerException("Unable to create local filename for '{$name}', object does not exists."); } //File should be removed after processing $tempFilename = $this->files->tempFilename($this->files->extension($name)); if (!ftp_get($this->connection, $tempFilename, $this->getPath($bucket, $name), FTP_BINARY)) { throw new ServerException("Unable to create local filename for '{$name}'."); } return $tempFilename; }
function downloadFile($fileFrom, $fileTo) { $mode = FTP_BINARY; // open some file to write to // $handle = fopen($fileTo, 'w'); // try to download $remote_file and save it to $handle if (ftp_get($this->connectionId, $fileTo, $fileFrom, $mode, 0)) { return true; $this->logMessage('File "' . $fileTo . '" successfully downloaded.'); } else { return false; $this->logMessage('There was an error downloading file "' . $fileFrom . '" to "' . $fileTo . '"'); } }
function fm_recursivemklocal($localdir, $prefix, $file) { global $ftp, $ftp_prepath; $cfiles = fm_fastgetfiles($prefix . $file); foreach ($cfiles as $i => $cfile) { if (endsWith($file, '/')) { fm_recursivemklocal($localdir . $cfile, $prefix, $file . $cfile); } else { @ftp_get($ftp, 'cache/down/temp.bin', $ftp_prepath . $prefix . $file . $cfile, FTP_BINARY); @chmod('cache/down/temp.bin', 0600); // Don't want those silly hackers @rename('cache/down/temp.bin', 'cache/down/local/' . $file . $cfile); } } }
/** * FTP 下载 * @param string $source * @param string $target * @param type $mode FTP_BINARY,FTP_ASCII * @return boolean */ public function download($source, $target, $mode = FTP_BINARY) { if (!$this->_isconn()) { return false; } $result = @ftp_get($this->conn_id, $target, $source, $mode); if ($result === false) { if ($this->debug === true) { $this->_log('ftp_unable_to_download: ' . $source . 'to ' . $target . ' '); } return false; } $this->_log('ftp down success'); return true; }
public function descargar_archivos($archivo, $conexion) { // var_dump($archivo); $segments = explode('/', rtrim($archivo, '/')); // var_dump($segments); $ruta_copiado_archivo = RUTA_RAIZ; for ($i = 2; $i < sizeof($segments); $i++) { $ruta_copiado_archivo .= '/' . $segments[$i]; } mkdir(dirname($ruta_copiado_archivo), 0777, true); $exito = ftp_get($conexion, $ruta_copiado_archivo, $archivo, FTP_BINARY); if (!$exito) { die('el archivo: ' . $archivo . ' fallo !'); } }
/** * Download file form FTP * @param $local_file - set file form local * @param $server_file - download file form server FTP * @param $format - format file * */ function get_file($local_file, $server_file, $format = null) { $only = null; if ($format != '') { $only = $this->only_format($server_file, $format); if ($only == false) { echo "Толькo формати jpg, png, gif\n"; return false; } } if (ftp_get($this->connect, $local_file, $server_file, FTP_BINARY)) { echo "Произведена запись в {$local_file}\n"; } else { echo "Не удалось завершить операцию\n"; } }
public function download($remoteFilename, $localFilename, $overwrite = false) { if (!$overwrite and file_exists($localFilename)) { throw new ConnectionException('File exists and overwrite flag is not set'); } if (!is_writable(dirname($localFilename))) { throw new ConnectionException('Local directory is not writable'); } if (!is_resource($this->resource)) { throw new ConnectionException('Connection is not open'); } if (!@ftp_get($this->resource, $localFilename, $remoteFilename, FTP_BINARY)) { throw new ConnectionException('Unable to download file'); } return $this; }
/** * Scarica un file dall'FTP * @param type $connection * @param string $local_file * @param string $server_file * @throws Exception */ public function downloadFile($local_file, $server_file) { $connection = $this->getConnection(); //TODO: switch per estensioni FTP_ASCII/FTP_BINARY switch (true) { default: $mode = FTP_ASCII; //FTP_BINARY se non è un file di testo } $res = ftp_get($connection, $local_file, $server_file, $mode); if (!$res) { throw new Exception("FTP HELPER: download failed {$server_file} > {$local_file}"); } else { Mage::helper('hevelop_gls')->debug("FTP HELPER: Downloaded {$server_file} > {$local_file}"); } }
function getFileFromFTP($url, $fileName) { $context = pobject::getContext(); $me = $context["arCurrentObject"]; require_once $me->store->get_config("code") . "modules/mod_mimemagic.php"; if (!$filename) { $filename = basename($url); } $result = false; preg_match('|([^:]+):([^@]+)@([^/]+).*$|i', $url, $matches); $file_artemp = tempnam($me->store->get_config("files") . "temp", "upload"); $ftpId = ftp_connect($matches[3]); ftp_login($ftpId, $matches[1], $matches[2]); ftp_get($ftpId, $file_artemp, $fileName, FTP_BINARY); readfile($file_artemp); return $result; }
public function downloadFile($fileFrom, $fileTo) { $asciiArray = array('txt', 'csv'); $fileParts = explode('.', $fileFrom); $extension = end($fileParts); if (in_array($extension, $asciiArray)) { $mode = FTP_ASCII; } else { $mode = FTP_BINARY; } if (ftp_get($this->connectionId, $fileTo, $fileFrom, $mode, 0)) { return true; $this->logMessage(' file "' . $fileTo . '" successfully downloaded'); } else { return false; $this->logMessage('There was an error downloading file "' . $fileFrom . '" to "' . $fileTo . '"'); } }