本文整理汇总了PHP中ftp_get函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_get函数的具体用法?PHP ftp_get怎么用?PHP ftp_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftp_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadFile
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;
}
示例2: get_file
/**
* 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;
}
}
}
示例3: GetMD5
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;
}
示例4: actionSynchronization
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);
}
示例5: lista_detallada
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;
}
示例6: get
/**
* @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;
}
示例7: get
function get($local, $remote, $mode = null)
{
if ($mode === null) {
$mode = FTP_BINARY;
}
return ftp_get($this->res, $local, $remote, $mode);
}
示例8: ftp_sync
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("..");
}
示例9: download
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);
}
}
示例10: get
/**
* 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);
}
}
示例11: download
/**
* 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;
}
示例12: download
public function download($file, $path, $mode = FTP_BINARY)
{
if (isset($file)) {
if (ftp_get($this->ftpcon, $path, $file, FTP_BINARY)) {
return true;
}
}
return false;
}
示例13: bajar_r
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;
}
示例14: copy_file
/**
* 方法:复制文件
* 说明:由于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);
}
示例15: copy_file
/**
* 方法:复制文件
* 说明:由于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);
}
}