本文整理汇总了PHP中ftp_nb_fget函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_nb_fget函数的具体用法?PHP ftp_nb_fget怎么用?PHP ftp_nb_fget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftp_nb_fget函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
function query($local_file, $remote_file)
{
if (!self::islogin()) {
if (!self::login()) {
return 0;
}
}
self::$temp_file = $local_file . self::$suffix;
self::$local_file = $local_file;
//self::$ret = @ftp_nb_get(self::$cid, self::$temp_file, self::$root.$remote_file, FTP_BINARY);
self::$fp = fopen(self::$temp_file, 'wb');
self::$ret = @ftp_nb_fget(self::$cid, self::$fp, self::$root . $remote_file, FTP_BINARY);
return self::$ret != FTP_FAILED;
}
示例2: download_xu
/**
* XU_Ftp::download_xu()
*
* Download a file
*
* @access public
* @param string $remote_file Remote filename
* @param string $fid File ID
* @param bool $max_size Max file size
* @return bool
*/
public function download_xu($remote_file, $fid, $max_size)
{
if (!$this->_is_conn()) {
return FALSE;
}
$result = TRUE;
// if no filepointer is given, make a temp file and open it for writing
$tmpfname = tempnam(ROOTPATH . '/temp', "RFT-");
$l_fp = fopen($tmpfname, "wb");
// Initate the download
$i = 0;
$CI =& get_instance();
$ret = ftp_nb_fget($this->conn_id, $l_fp, $remote_file, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
if ($i % 10 == 0) {
$fstat = fstat($l_fp);
$p = $fstat[7];
$CI->db->where('fid', $fid);
$CI->db->update('progress', array('progress' => $p, 'curr_time' => time()));
}
// Continue downloading...
$ret = ftp_nb_continue($this->conn_id);
$i++;
}
// Has it finished completly?
if ($ret != FTP_FINISHED) {
log_message('error', "FTP TRANSFER FAILED");
$result = FALSE;
}
if ($result === FALSE) {
if ($this->debug == TRUE) {
$msg = 'ftp_unable_to_download';
$this->_error($msg);
} else {
$this->error = TRUE;
$this->error_msg = 'ftp_unable_to_download';
}
return FALSE;
}
return $tmpfname;
}
示例3: nbFget
/**
* 从检索FTP服务器上的文件并将其写入一个打开的文件(非阻塞)
*
* @param resource $handle
* @param string $remote_file
* @param int $mode
* @param int $resumepos
* @return int 返回ftp_failed或ftp_finished或ftp_moredata
*/
public static function nbFget($handle, $remote_file, $mode = FTP_ASCII, $resumepos = 0)
{
return ftp_nb_fget(self::$resource, $handle, $remote_file, $mode, $resumepos);
}
示例4: get
public function get($local_file_path, $remote_file_path, $mode = FTP_BINARY, $resume = false, $updraftplus = false)
{
$file_last_size = 0;
if ($resume) {
if (!($fh = fopen($local_file_path, 'ab'))) {
return false;
}
clearstatcache($local_file_path);
$file_last_size = filesize($local_file_path);
} else {
if (!($fh = fopen($local_file_path, 'wb'))) {
return false;
}
}
// Implicit FTP, for which we use curl (since PHP's native FTP functions don't handle implicit FTP)
if ($this->curl_handle) {
if ($resume) {
curl_setopt($this->curl_handle, CURLOPT_RESUME_FROM, $resume);
}
curl_setopt($this->curl_handle, CURLOPT_NOBODY, false);
curl_setopt($this->curl_handle, CURLOPT_URL, 'ftps://' . $this->host . '/' . $remote_file_path);
curl_setopt($this->curl_handle, CURLOPT_UPLOAD, false);
curl_setopt($this->curl_handle, CURLOPT_FILE, $fh);
$output = curl_exec($this->curl_handle);
if ($output) {
if ($updraftplus) {
$updraftplus->log("FTP fetch: fetch complete");
}
} else {
if ($updraftplus) {
$updraftplus->log("FTP fetch: fetch failed");
}
}
return $output;
}
$ret = ftp_nb_fget($this->conn_id, $fh, $remote_file_path, $mode, $file_last_size);
if (false == $ret) {
return false;
}
while ($ret == FTP_MOREDATA) {
if ($updraftplus) {
$file_now_size = filesize($local_file_path);
if ($file_now_size - $file_last_size > 524288) {
$updraftplus->log("FTP fetch: file size is now: " . sprintf("%0.2f", filesize($local_file_path) / 1048576) . " Mb");
$file_last_size = $file_now_size;
}
clearstatcache();
}
$ret = ftp_nb_continue($this->conn_id);
}
fclose($fh);
if ($ret == FTP_FINISHED) {
if ($updraftplus) {
$updraftplus->log("FTP fetch: fetch complete");
}
return true;
} else {
if ($updraftplus) {
$updraftplus->log("FTP fetch: fetch failed");
}
return false;
}
}
示例5: downloadToFileUnobtrusive
/**
* Downloads a file from the FTP server and saves to an open file but does not block other operations
*
* @param string $remotefile Remote path of the file to download
* @param string $resource Resource handle of the open file in which the downloaded file should be written
* @param string $mode Transfer mode for the file. (auto or ascii or binary)
* @param integer $position Pointer of the remote file from where the download should be resumed
* @return integer 0 = Transfer failed (FTP_FAILED) | 1 = Transfer finished (FTP_FINISHED) | 2 = Transfer in progress (FTP_MOREDATA)
*/
public function downloadToFileUnobtrusive($remotefile, $resource, $mode = 'auto', $position = null)
{
if (is_resource($this->cid)) {
$transfermode = self::transferMode($mode);
return ftp_nb_fget($this->cid, $resource, $remotefile, $transfermode, $position);
}
}
示例6: fget
/**
* This function will download a file from the ftp-server. You can either spcify a absolute
* path to the file (beginning with "/") or a relative one, which will be completed
* with the actual directory you selected on the server. You can specify
* the path to which the file will be downloaded on the local
* maschine, if the file should be overwritten if it exists (optionally, default is
* no overwriting) and in which mode (FTP_ASCII or FTP_BINARY) the file should be
* downloaded (if you do not specify this, the method tries to determine it automatically
* from the mode-directory or uses the default-mode, set by you). If you give a relative
* path to the local-file, the script-path is used as basepath.
*
* @access public
* @param string $remote_file The absolute or relative path to the file to download
* @param handle $local_hanlde The local file pointer to put the downloaded in
* @param int $mode (optional) Either FTP_ASCII or FTP_BINARY
* @return mixed True on success, otherwise PEAR::Error
* @see NET_FTP_ERR_OVERWRITELOCALFILE_FORBIDDEN, NET_FTP_ERR_OVERWRITELOCALFILE_FAILED, NET_FTP_ERR_OVERWRITELOCALFILE_FAILED
*/
function fget($remote_file, $local_handle, $mode = null)
{
if (!isset($mode)) {
$mode = $this->checkFileExtension($remote_file);
}
$remote_file = $this->_construct_path($remote_file);
if (@function_exists('ftp_nb_fget')) {
$res = @ftp_nb_fget($this->_handle, $local_handle, $remote_file, $mode);
while ($res == FTP_MOREDATA) {
$this->_announce('nb_fget');
$res = @ftp_nb_continue($this->_handle);
}
} else {
$res = @ftp_fget($this->_handle, $local_handle, $remote_file, $mode);
}
if (!$res) {
return $this->raiseError("File '{$remote_file}' could not be downloaded.", NET_FTP_ERR_OVERWRITELOCALFILE_FAILED);
} else {
return true;
}
}
示例7: 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_fget_basic3.txt";
file_put_contents($local_file, 'ASCIIFoo');
$handle = fopen($local_file, 'a');
var_dump(ftp_nb_fget($ftp, $handle, 'fgetresume.txt', FTP_ASCII, 8));
var_dump(file_get_contents($local_file));
@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_nb_fget_basic3.txt");
示例8: ftp_connect
<?php
$bogus = 1;
require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) {
die("Couldn't connect to the server");
}
var_dump(ftp_login($ftp, 'anonymous', 'mail@example.com'));
var_dump(ftp_alloc($ftp, 400));
var_dump(ftp_cdup($ftp));
var_dump(ftp_chdir($ftp, '~'));
var_dump(ftp_chmod($ftp, 0666, 'x'));
var_dump(ftp_delete($ftp, 'x'));
var_dump(ftp_exec($ftp, 'x'));
var_dump(ftp_fget($ftp, STDOUT, 'x', 0));
var_dump(ftp_fput($ftp, 'x', fopen(__FILE__, 'r'), 0));
var_dump(ftp_get($ftp, 'x', 'y', 0));
var_dump(ftp_mdtm($ftp, 'x'));
var_dump(ftp_mkdir($ftp, 'x'));
var_dump(ftp_nb_continue($ftp));
var_dump(ftp_nb_fget($ftp, STDOUT, 'x', 0));
var_dump(ftp_nb_fput($ftp, 'x', fopen(__FILE__, 'r'), 0));
var_dump(ftp_systype($ftp));
var_dump(ftp_pwd($ftp));
var_dump(ftp_size($ftp, ''));
var_dump(ftp_rmdir($ftp, ''));
示例9: getContents
public function getContents($path)
{
$path = $this->path($path);
// Create stack buffer
Engine_Stream_Stack::registerWrapper();
$stack = fopen('stack://tmp');
if (!$stack) {
throw new Engine_Vfs_Adapter_Exception(sprintf('Unable to create stack buffer'));
}
// Get mode
$mode = $this->getFileMode($path);
// Non-blocking mode
if (@function_exists('ftp_nb_fget')) {
$resource = $this->getResource();
$res = @ftp_nb_fget($resource, $stack, $path, $mode);
while ($res == FTP_MOREDATA) {
//$this->_announce('nb_get');
$res = @ftp_nb_continue($resource);
}
$return = $res === FTP_FINISHED;
} else {
$return = @ftp_fget($this->_handle, $stack, $path, $mode);
}
if (!$return) {
throw new Engine_Vfs_Adapter_Exception(sprintf('Unable to get contents of "%s"', $path));
}
$data = '';
while (false != ($dat = fread($stack, 1024))) {
$data .= $dat;
}
return $data;
}
示例10: get
public function get($local_file_path, $remote_file_path, $mode = FTP_BINARY, $resume = false, $updraftplus = false)
{
$file_last_size = 0;
if ($resume) {
if (!($fh = fopen($local_file_path, 'ab'))) {
return false;
}
clearstatcache($local_file_path);
$file_last_size = filesize($local_file_path);
} else {
if (!($fh = fopen($local_file_path, 'wb'))) {
return false;
}
}
$ret = ftp_nb_fget($this->conn_id, $fh, $remote_file_path, $mode, $file_last_size);
if (false == $ret) {
return false;
}
while ($ret == FTP_MOREDATA) {
if ($updraftplus) {
$file_now_size = filesize($local_file_path);
if ($file_now_size - $file_last_size > 524288) {
$updraftplus->log("FTP fetch: file size is now: " . sprintf("%0.2f", filesize($local_file_path) / 1048576) . " Mb");
$file_last_size = $file_now_size;
}
clearstatcache($local_file_path);
}
$ret = ftp_nb_continue($this->conn_id);
}
fclose($fh);
if ($ret == FTP_FINISHED) {
if ($updraftplus) {
$updraftplus->log("FTP fetch: fetch complete");
}
return true;
} else {
if ($updraftplus) {
$updraftplus->log("FTP fetch: fetch failed");
}
return false;
}
}
示例11: ftp_nb_fget
public function ftp_nb_fget($conn, $fp, $file, $mode)
{
return ftp_nb_fget($conn, $fp, $file, $mode);
}
示例12: 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));
示例13: download_xu2
/**
* Download a file
*
*/
function download_xu2($remote_file, $fid, $max_size)
{
if (!$this->_is_conn()) {
return FALSE;
}
$result = TRUE;
// TODO: Make this use cache.
$tmpfname = tempnam('./temp', 'RFT-');
$l_fp = fopen($tmpfname, "wb");
$i = 0;
$CI =& get_instance();
$ret = ftp_nb_fget($this->conn_id, $l_fp, $remote_file, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
if ($i % 10 == 0) {
$fstat = fstat($l_fp);
$p = $fstat[7];
$CI->db->where('fid', $fid);
$CI->db->update('progress', array('progress' => $p, 'curr_time' => time()));
}
// Continue downloading...
$ret = ftp_nb_continue($this->conn_id);
$i++;
}
if ($ret != FTP_FINISHED) {
log_message('error', 'FTP TRANSFER FAILED');
$result = FALSE;
}
if ($result === FALSE) {
if ($this->debug == TRUE) {
$msg = 'ftp_unable_to_download';
$this->_error($msg);
} else {
$this->error = TRUE;
$this->error_msg = 'ftp_unable_to_download';
}
return FALSE;
}
return $tmpfname;
}
示例14: download
public function download()
{
// remove session
if (isset($_SESSION['showDownload'])) {
// reset session variable for next time
$_SESSION['showDownload'] = null;
unset($_SESSION['showDownload']);
session_write_close();
}
// php script timeout for long downloads (2 days!)
set_time_limit(60 * 60 * 24 * 2);
// load the server the file is on
$storageType = 'local';
$storageLocation = _CONFIG_FILE_STORAGE_PATH;
$uploadServerDetails = $this->loadServer();
if ($uploadServerDetails != false) {
$storageLocation = $uploadServerDetails['storagePath'];
$storageType = $uploadServerDetails['serverType'];
// if no storage path set & local, use system default
if (strlen($storageLocation) == 0 && $storageType == 'local') {
$storageLocation = _CONFIG_FILE_STORAGE_PATH;
}
}
// get file path
$fullPath = $this->getFullFilePath($storageLocation);
// open file - via ftp
if ($storageType == 'remote') {
// connect via ftp
$conn_id = ftp_connect($uploadServerDetails['ipAddress'], $uploadServerDetails['ftpPort'], 30);
if ($conn_id === false) {
$this->errorMsg = 'Could not connect to ' . $uploadServerDetails['ipAddress'] . ' to upload file.';
return false;
}
// authenticate
$login_result = ftp_login($conn_id, $uploadServerDetails['ftpUsername'], $uploadServerDetails['ftpPassword']);
if ($login_result === false) {
$this->errorMsg = 'Could not login to ' . $uploadServerDetails['ipAddress'] . ' with supplied credentials.';
return false;
}
// prepare the stream of data
$pipes = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
if ($pipes === false) {
$this->errorMsg = 'Could not create stream to download file on ' . $uploadServerDetails['ipAddress'];
return false;
}
stream_set_write_buffer($pipes[0], 10000);
stream_set_timeout($pipes[1], 10);
stream_set_blocking($pipes[1], 0);
$fail = false;
$ret = ftp_nb_fget($conn_id, $pipes[0], $fullPath, FTP_BINARY, FTP_AUTORESUME);
} else {
$handle = @fopen($fullPath, "r");
if (!$handle) {
$this->errorMsg = 'Could not open file for reading.';
return false;
}
}
// download speed
$speed = 0;
// if free/non user
$Auth = Auth::getAuth();
if ($Auth->loggedIn == false || $Auth->level == 'free user') {
$speed = (int) SITE_CONFIG_FREE_USER_MAX_DOWNLOAD_SPEED;
} else {
$speed = (int) SITE_CONFIG_PREMIUM_USER_MAX_DOWNLOAD_SPEED;
}
// do we need to throttle the speed?
if ($speed > 0) {
// create new throttle config
$config = new ThrottleConfig();
// set standard transfer rate (in bytes/second)
$config->burstLimit = $speed;
$config->rateLimit = $speed;
// enable module (this is a default value)
$config->enabled = true;
// start throttling
$x = new Throttle($config);
}
// output some headers
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: " . $this->fileType);
header("Pragma: public");
header("Content-Disposition: attachment; filename=\"" . str_replace("\"", "", $this->originalFilename) . "\"");
header("Content-Description: File Transfer");
header("Content-Length: " . $this->fileSize);
// output file - via ftp
if ($storageType == 'remote') {
while ($ret == FTP_MOREDATA) {
$contents = stream_get_contents($pipes[1]);
if ($contents !== false) {
echo $contents;
flush();
}
$ret = ftp_nb_continue($conn_id);
}
/*
$contents = stream_get_contents($pipes[1]);
if($contents !== false)
{
//.........这里部分代码省略.........
示例15: 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");
}
ftp_set_option($ftp, FTP_AUTOSEEK, false);
$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_nb_fget_basic1.txt";
$handle = fopen($local_file, 'w');
var_dump(ftp_nb_fget($ftp, $handle, 'fget.txt', FTP_ASCII, FTP_AUTORESUME));
var_dump(file_get_contents($local_file));