当前位置: 首页>>代码示例>>PHP>>正文


PHP ftp_nb_get函数代码示例

本文整理汇总了PHP中ftp_nb_get函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_nb_get函数的具体用法?PHP ftp_nb_get怎么用?PHP ftp_nb_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ftp_nb_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: download

 /**
  * FTP-文件下载
  *
  * @param string  $local_file 本地文件
  * @param string  $ftp_file Ftp文件
  *
  * @return bool
  */
 public function download($local_file, $ftp_file)
 {
     if (empty($local_file) || empty($ftp_file)) {
         return false;
     }
     $ret = ftp_nb_get($this->linkid, $local_file, $ftp_file, FTP_BINARY);
     while ($ret == FTP_MOREDATA) {
         $ret = ftp_nb_continue($this->linkid);
     }
     if ($ret != FTP_FINISHED) {
         return false;
     }
     return true;
 }
开发者ID:phpdn,项目名称:framework,代码行数:22,代码来源:Ftp.php

示例2: down

 function down($file, $name = "")
 {
     if (!$file) {
         return false;
     }
     if (!$name) {
         $name = basename($file);
     }
     $rs = ftp_nb_get($this->conn, $file, $file, FTP_BINARY);
     while ($res == FTP_MOREDATA) {
         $res = ftp_nb_continue($this->conn);
     }
     if ($res == FTP_FINISHED) {
         return true;
     } elseif ($res == FTP_FAILED) {
         return false;
     }
 }
开发者ID:norain2050,项目名称:hkgbf,代码行数:18,代码来源:ftp.php

示例3: downloadFile

 /**
  * 下载文件(支持全新下载和断点下载)
  * @uses $exist = file_exists($local)  <br>
  * <pre>
  * 1、指定的本地文件存在
  * 		1.1全新:选定了全新下载,但指定的本地文件已存在
  * 			(开发者可根据此状态来询问客户端是否需要覆盖本地文件)<br>
  * 			(当客户端决定覆盖上传时,应该先使服务器备份指定的本地文件,再继续全新下载)<br>
  * 		1.2续传:正常执行断点下载
  * 2、指定的本地文件不存在
  * 		2.1全新:正常执行全新下载
  * 		2.2续传:选定了断点下载,但指定的本地文件不存在
  * 			(开发者可根据此状态来询问客户端是否要继续下载)<br>
  * 			(当客户端决定继续下载时,应该采用全新下载方式)<br>
  * </pre>
  * @param string $local 本地文件路径(如e:\abc\def.txt或./a/b/c.txt)
  * @param string $remote 远程文件全路径(如/a/b/c.txt)
  * @param boolean $isContinue 是否断点续传,默认为false,全新下载
  * @return int 下载状态<br>
  * 		AiFtpStatus::DOWNLOAD_FILE_SUCCESS为上传成功,<br>
  * 		其它值为下载失败。<br>
  * 		上传失败的原因一般有:连接断开、编码错误、远程文件不存在、本地文件已存在等等<br>
  */
 function downloadFile($local, $remote, $isContinue = false)
 {
     $local = $this->scriptToFsCharset($local);
     $remote = $this->upcharconv($remote);
     if (-1 == ftp_size($this->stream, $remote)) {
         return $isContinue ? AiFtpStatus::DOWNLOAD_HALF_FILE_HASNO_REMOTEFILE : AiFtpStatus::DOWNLOAD_NEW_FILE_HASNO_REMOTEFILE;
     }
     $ret = null;
     if (file_exists($local)) {
         if (!$isContinue) {
             return AiFtpStatus::DOWNLOAD_NEW_FILE_EXIST_LOCALFILE;
         }
         //ftp_set_option($this->stream, FTP_AUTOSEEK, false);//禁止自动搜寻断点开始处
         @($ret = ftp_nb_get($this->stream, $local, $remote, FTP_BINARY, filesize($local)));
     } else {
         if ($isContinue) {
             return AiFtpStatus::DOWNLOAD_HALF_FILE_HASNO_LOCALFILE;
         }
         @($ret = ftp_nb_get($this->stream, $local, $remote, FTP_BINARY));
     }
     while (FTP_MOREDATA == $ret) {
         $ret = ftp_nb_continue($this->stream);
     }
     if (FTP_FINISHED != $ret) {
         return $isContinue ? AiFtpStatus::DOWNLOAD_HALF_FILE_UN_FINISH : AiFtpStatus::DOWNLOAD_NEW_FILE_UN_FINISH;
     }
     return AiFtpStatus::DOWNLOAD_FILE_SUCCESS;
 }
开发者ID:gxflying,项目名称:OpenAI,代码行数:51,代码来源:AiFtp.class.php

示例4: ftp_connect

<?php

require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
ftp_login($ftp, 'user', 'pass');
if (!$ftp) {
    die("Couldn't connect to the server");
}
$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_nb_get_large.txt";
touch($local_file);
ftp_nb_get($ftp, $local_file, 'fget_large.txt', FTP_BINARY, 5368709119);
$fp = fopen($local_file, 'r');
fseek($fp, 5368709119);
var_dump(fread($fp, 1));
var_dump(filesize($local_file));
fclose($fp);
@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_nb_get_large.txt");
开发者ID:alphaxxl,项目名称:hhvm,代码行数:17,代码来源:ftp_nb_get_large.php

示例5: ftp_get_file

function ftp_get_file($opts, $pipe = false, $cmd = __FUNCTION__)
{
    # set prefix
    $prefix = 'ftp';
    # merge opts
    $opts = merge_opts($opts, $pipe, 'remote_file');
    # get execute opt
    $execute = get_opt_config_value($prefix, $opts, 'execute', true);
    if (!check_opt_set_type($cmd, $execute, 'execute', 'boolean')) {
        return false;
    }
    # check if we should execute or not
    if (!$execute) {
        return true;
    }
    # get remote file opt
    $remote_file = get_opt($prefix, $opts, 'remote_file');
    if (!check_opt_set_type($cmd, $remote_file, 'remote_file', 'string')) {
        return false;
    }
    # get local file opt
    $local_file = get_opt($prefix, $opts, 'local_file', $remote_file);
    if (!check_opt_set_type($cmd, $local_file, 'local_file', 'string')) {
        return false;
    }
    # get get retries opt
    $get_retries = get_opt_config_value($prefix, $opts, 'get_retries', 3);
    if (!check_opt_set_type($cmd, $get_retries, 'get_retries', 'integer')) {
        return false;
    }
    # get download progress update opt
    $download_progress_update = get_opt_config_value($prefix, $opts, 'download_progress_update', true);
    if (!check_opt_set_type($cmd, $download_progress_update, 'download_progress_update', 'boolean')) {
        return false;
    }
    # check to see if we shall re-use the file if it already exists
    if (is_file($local_file)) {
        $use_saved_file = get_opt_config_value($prefix, $opts, 'use_saved_file', true);
        if (!check_opt_set_type($cmd, $use_saved_file, 'use_saved_file', 'boolean')) {
            return false;
        }
        # get backup old downloaded files
        $backup_old_saved_files = get_opt_config_value($prefix, $opts, 'backup_old_saved_files', true);
        if (!check_opt_set_type($cmd, $backup_old_saved_files, 'backup_old_saved_files', 'boolean')) {
            return false;
        }
        if ($use_saved_file) {
            debug_echo($cmd, "using saved file instead of executing the FTP request : {$local_file}");
            return array('file' => $local_file);
        } elseif ($backup_old_saved_files && !backup_file($local_file)) {
            return error($cmd, "could not backup previously downloaded file : {$local_file}");
        }
    }
    # setup connection
    $conn = ftp_get_conn($opts, $cmd);
    if (!$conn) {
        return false;
    }
    # get connection values
    $ftp_handle = $conn['handle'];
    $svr = $conn['svr'];
    # make the parent dir of local file
    if (!make_dir(dirname($local_file), $opts, $cmd)) {
        return false;
    }
    # get the size of the remote file
    $size = ftp_size($ftp_handle, $remote_file);
    if ($size == -1) {
        debug_echo($cmd, "fetching file from FTP server : {$remote_file} => {$local_file} (unknown size) ...");
    } else {
        $size_str = human_filesize($size);
        debug_echo($cmd, "fetching file from FTP server : {$remote_file} => {$local_file} (size: {$size_str}) ...");
    }
    # get the file
    if ($download_progress_update) {
        # get the file with a progress monitor (a little slower)
        for ($j = 0; $j < $get_retries; $j++) {
            $ret = ftp_nb_get($ftp_handle, $local_file, $remote_file, FTP_BINARY);
            while ($ret == FTP_MOREDATA) {
                # get the size of the downloaded file (note: we need to use file handlers otherwise it doesn't work)
                $fh = fopen($local_file, 'r');
                $stat = fstat($fh);
                $dl_size = $stat['size'];
                fclose($fh);
                # print progress
                download_progress($size, $dl_size);
                # continue downloading
                $ret = ftp_nb_continue($ftp_handle);
            }
            if ($ret == FTP_FINISHED) {
                return array('file' => $local_file);
            }
        }
    } else {
        # get local handle
        $local_file_handle = fopen($local_file, 'w');
        if (!$local_file_handle) {
            return error($cmd, "could not open local file : {$local_file}");
        }
        # get the file without a progress monitor (a bit quicker)
//.........这里部分代码省略.........
开发者ID:simpl,项目名称:datapipe,代码行数:101,代码来源:ftp.php

示例6: get

 /**
  * Download a file from FTP server.
  * 
  * @param	string local file
  * @param	string remote file The remote file path.
  * @param	const  mode The transfer mode. Must be either <strong>FTP_ASCII</strong> or <strong>FTP_BINARY</strong>.
  * @param boolean $asynchronous  Flag indicating if file transfert should block php application or not.
  * @return	boolean
  */
 public function get($remote, $local = null, $mode = FTP_BINARY, $asynchronous = false)
 {
     if ($this->getActive()) {
         if (!isset($local) || $local == null || !is_string($local) || trim($local) == '') {
             $local = getcwd() . DIRECTORY_SEPARATOR . basename($remote);
         }
         // Get the requested file
         if ($asynchronous === false) {
             if (ftp_get($this->_connection, $local, $remote, $mode)) {
                 // If successful, return the path to the downloaded file...
                 return $remote;
             } else {
                 return false;
             }
         } else {
             $ret = ftp_nb_get($this->_connection, $local, $remote, $mode);
             while ($ret == FTP_MOREDATA) {
                 // continue downloading
                 $ret = ftp_nb_continue($this->_connection);
             }
             if ($ret == FTP_FAILED) {
                 return false;
             } else {
                 return $remote;
             }
         }
     } else {
         throw new \Exception('EFtpComponent is inactive and cannot perform any FTP operations.');
     }
 }
开发者ID:jymsy,项目名称:sky2,代码行数:39,代码来源:Ftp.php

示例7: getFile

	/**
	 * Get file
	 * @param $path The remote file path
	 * @param $l Lang
	 * @param $overwrite Overwrite the target file
	 */
	public static function getFile($path, $l, $overwrite){
		try{
			$pathinfo = pathinfo($path);
			$fs = OCP\Files::getStorage('files');
			if($fs->file_exists('/Downloads/' . $pathinfo['basename']) && !$overwrite){
				$pathinfo['basename'] = md5(rand()) . '_' . $pathinfo['basename'];
			}
			
			$size = self::getRemoteFileSize($path);
			if($size == 0){
				OC_ocDownloaderPB::setError($l->t('Filesize is null'));
				self::closeConnection();
				exit();
			}
			$chunkSize = self::getChunkSize($size);
			
			$received = $last = 0;
			$ret = ftp_nb_get(self::$conn, $fs->getLocalFile('/Downloads/' . $pathinfo['basename']), $path, FTP_BINARY);
			while($ret == FTP_MOREDATA){
				$received += $fs->filesize('/Downloads/' . $pathinfo['basename']);
				if($received >= $size){
	                $percent = 100;
	            }else{
	                $percent = @round(($received/$size)*100, 2);
	            }
				
				if($received > $last + $chunkSize){
					OC_ocDownloaderPB::setProgressBarProgress($percent);
					$last = $received;
				}
				
				usleep(100);
			   	$ret = ftp_nb_continue(self::$conn);
			}
			if($ret != FTP_FINISHED){
			   	OC_ocDownloaderPB::setError($l->t('Download error'));
				self::closeConnection();
			   	exit();
			}else{
				OC_ocDownloaderPB::setProgressBarProgress(100);
				OC_ocDownloader::setUserHistory($pathinfo['basename'], 1);
			}
			
			self::closeConnection();
		}catch(exception $e){
			OC_ocDownloaderPB::setError($l->t('Unknown error'));
		}
	}
开发者ID:ArcherSys,项目名称:ArcherSysOSCloud7,代码行数:54,代码来源:ocDownloaderFTP.class.php

示例8: var_dump

<?php

$ftp = null;
var_dump(ftp_connect(array()));
var_dump(ftp_connect('127.0.0.1', 0, -3));
var_dump(ftp_raw($ftp));
var_dump(ftp_mkdir($ftp));
var_dump(ftp_rmdir($ftp));
var_dump(ftp_nlist($ftp));
var_dump(ftp_rawlist($ftp));
var_dump(ftp_fget($ftp));
var_dump(ftp_nb_fget($ftp));
var_dump(ftp_nb_get($ftp));
var_dump(ftp_pasv($ftp));
var_dump(ftp_nb_continue());
var_dump(ftp_fput());
var_dump(ftp_nb_fput($ftp));
var_dump(ftp_put($ftp));
var_dump(ftp_nb_put($ftp));
var_dump(ftp_size($ftp));
var_dump(ftp_mdtm($ftp));
var_dump(ftp_rename($ftp));
var_dump(ftp_site($ftp));
var_dump(ftp_set_option($ftp));
var_dump(ftp_get_option($ftp));
开发者ID:badlamer,项目名称:hhvm,代码行数:25,代码来源:006.php

示例9: ftp_connect

<?php

require 'server.inc';
$file = "mediumfile.txt";
$ftp = ftp_connect('127.0.0.1', $port);
ftp_login($ftp, 'user', 'pass');
if (!$ftp) {
    die("Couldn't connect to the server");
}
$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $file;
touch($local_file);
$r = ftp_nb_get($ftp, $local_file, $file, FTP_BINARY);
while ($r == FTP_MOREDATA) {
    $r = ftp_nb_continue($ftp);
}
ftp_close($ftp);
echo file_get_contents($local_file);
error_reporting(0);
@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "mediumfile.txt");
开发者ID:badlamer,项目名称:hhvm,代码行数:19,代码来源:ftp_nb_continue.php

示例10: nb_get

 protected function nb_get($localfile, $remotefile, $start = FTP_AUTORESUME)
 {
     clearstatcache();
     if (!file_exists($localfile)) {
         $start = 0;
     }
     $ret = @ftp_nb_get($this->connexion, $localfile, $remotefile, FTP_BINARY, $start);
     while ($ret === FTP_MOREDATA) {
         set_time_limit(20);
         $ret = ftp_nb_continue($this->connexion);
     }
     return $ret;
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:13,代码来源:ftpclient.php

示例11: get

 /**
  * @param $local
  * @param $path
  *
  * @return bool
  */
 public function get($local, $path)
 {
     $path = $this->getPath($path);
     $mode = $this->getFileMode($path);
     // Non-blocking mode
     if (@function_exists('ftp_nb_get')) {
         $resource = $this->getResource();
         $res = @ftp_nb_get($resource, $local, $path, $mode);
         while ($res == FTP_MOREDATA) {
             $res = @ftp_nb_continue($resource);
         }
         $return = $res === FTP_FINISHED;
     } else {
         $return = @ftp_get($this->_handle, $local, $path, $mode);
     }
     if (!$return) {
         throw new DriverException(sprintf('Unable to get "%s" to "%s"', $path, $local));
     }
     return true;
 }
开发者ID:kendolabdev,项目名称:kendoplatform,代码行数:26,代码来源:FtpDriver.php

示例12: pull

 /**
  * FTP中文件下载到本地
  *
  * @params array $params 参数 array('local'=>'本地文件路径','remote'=>'远程文件路径','resume'=>'文件指针位置')
  * @params string $msg 
  * @return bool 
  */
 public function pull($params, &$msg)
 {
     if ($this->ftp_extension) {
         $ret = ftp_nb_get($this->conn, $params['local'], $params['remote'], $this->mode, $params['resume']);
         while ($ret == FTP_MOREDATA) {
             $ret = ftp_nb_continue($this->conn);
         }
     } else {
         $ret = $this->ftpclient->download($params['remote'], $params['local'], $this->mode, $params['resume']);
     }
     if ($ret == FTP_FAILED || $ret === false) {
         $msg = app::get('importexport')->_('FTP下载文件失败');
         return false;
     }
     return true;
 }
开发者ID:453111208,项目名称:bbc,代码行数:23,代码来源:ftp.php

示例13: get

 public function get($local, $path)
 {
     $path = $this->path($path);
     // Get mode
     $mode = $this->getFileMode($path);
     // Non-blocking mode
     if (@function_exists('ftp_nb_get')) {
         $resource = $this->getResource();
         $res = @ftp_nb_get($resource, $local, $path, $mode);
         while ($res == FTP_MOREDATA) {
             //$this->_announce('nb_get');
             $res = @ftp_nb_continue($resource);
         }
         $return = $res === FTP_FINISHED;
     } else {
         $return = @ftp_get($this->_handle, $local, $path, $mode);
     }
     // Error
     if (!$return) {
         throw new Engine_Vfs_Adapter_Exception(sprintf('Unable to get "%s" to "%s"', $path, $local));
     }
     return true;
 }
开发者ID:robeendey,项目名称:ce,代码行数:23,代码来源:Ftp.php

示例14: nbGet

 /**
  *
  * 从 FTP 服务器上获取文件并写入本地文件(non-blocking)
  *
  * @param string $local_file
  * @param string $remote_file
  * @param int $mode
  * @param int $resumepos
  * @return int  返回 FTP_FAILED,FTP_FINISHED 或 FTP_MOREDATA
  */
 public static function nbGet($local_file, $remote_file, $mode = FTP_ASCII, $resumepos = 0)
 {
     return ftp_nb_get(self::$resource, $local_file, $remote_file, $mode, $resumepos);
 }
开发者ID:luozhanhong,项目名称:share,代码行数:14,代码来源:ftp.php

示例15: get

 /**
  * @see RemoteDriver::get($mode, $remote_file, $local_file, $asynchronous)
  */
 public function get($remote_file, $local_file = null, $mode = FTP_ASCII, $asynchronous = false)
 {
     $this->connectIfNeeded();
     if (!isset($local_file) || $local_file == null || !is_string($local_file) || trim($local_file) == "") {
         $local_file = getcwd() . DIRECTORY_SEPARATOR . basename($remote_file);
     }
     $this->param = array('remote_file' => $remote_file, 'local_file' => $local_file, 'asynchronous' => $asynchronous);
     if ($asynchronous !== true) {
         if (!ftp_get($this->handle, $local_file, $remote_file, $mode)) {
             throw new FtpException(Yii::t('gftp', 'Could not synchronously get file "{remote_file}" from server "{host}"', ['host' => $this->host, 'remote_file' => $remote_file]));
         }
     } else {
         $ret = ftp_nb_get($this->handle, $local_file, $remote_file, $mode);
         while ($ret == FTP_MOREDATA) {
             // continue downloading
             $ret = ftp_nb_continue($this->handle);
         }
         if ($ret == FTP_FAILED) {
             throw new FtpException(Yii::t('gftp', 'Could not asynchronously get file "{remote_file}" from server "{host}"', ['host' => $this->host, 'remote_file' => $remote_file]));
         }
     }
     return realpath($local_file);
 }
开发者ID:komaspieler,项目名称:yii2-gftp,代码行数:26,代码来源:FtpDriver.php


注:本文中的ftp_nb_get函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。