本文整理汇总了PHP中ftp_nb_continue函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_nb_continue函数的具体用法?PHP ftp_nb_continue怎么用?PHP ftp_nb_continue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftp_nb_continue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: syncFolderToFtp
function syncFolderToFtp($host, $username, $password, $remote_backup, $backup_folder)
{
$ftp = ftp_connect($host);
// connect to the ftp server
ftp_login($ftp, $username, $password);
// login to the ftp server
ftp_chdir($ftp, $remote_backup);
// cd into the remote backup folder
// copy files from folder to remote folder
$files = glob($backup_folder . '*');
$c = 0;
$allc = count($files);
foreach ($files as $file) {
$c++;
$file_name = basename($file);
echo "\n {$c}/{$allc}: {$file_name}";
$upload = ftp_nb_put($ftp, $file_name, $file, FTP_BINARY);
// non-blocking put, uploads the local backup onto the remote server
while ($upload == FTP_MOREDATA) {
// Continue uploading...
$upload = ftp_nb_continue($ftp);
}
if ($upload != FTP_FINISHED) {
echo " ... ERROR";
} else {
echo " ... OK";
}
}
ftp_close($ftp);
// closes the connection
}
示例2: 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;
}
示例3: put
function put($localFile, $remoteFile = '')
{
if ($remoteFile == '') {
$remoteFile = end(explode('/', $localFile));
}
$res = ftp_nb_put($this->ftpR, $remoteFile, $localFile, FTP_BINARY);
while ($res == FTP_MOREDATA) {
$res = ftp_nb_continue($this->ftpR);
}
if ($res == FTP_FINISHED) {
return true;
} elseif ($res == FTP_FAILED) {
return false;
}
}
示例4: __construct
/**
* Construct the routine that must be run.
*
* @param array $files Files to upload
* @param array $options FTP Connection options.
*
* @return void
*/
public function __construct($files, $options = [])
{
parent::__construct();
$this->_sig_complete = new SIG_Complete();
$this->_sig_failure = new SIG_Failure();
$this->_sig_finished = new SIG_Finished($this);
$defaults = ['hostname' => null, 'port' => 21, 'timeout' => 90, 'username' => null, 'password' => null, 'secure' => false];
$this->_files = $files;
$options += $defaults;
$this->_options = $options;
/**
* Upload Idle process
*/
$this->_idle = new Process(function () {
$this->_init_transfers();
foreach ($this->_uploading as $_key => $_file) {
$status = ftp_nb_continue($_file[0]);
if ($status === FTP_MOREDATA) {
continue;
}
if ($status === FTP_FINISHED) {
$this->_sig_complete->set_upload($_file[1]);
xp_emit($this->_sig_complete);
// Close the FTP connection to that file
ftp_close($_file[0]);
$this->_uploaded[] = $_file[1];
} else {
$this->_sig_failure->set_upload($_file[1]);
xp_emit($this->_sig_failure);
// Close the FTP connection to that file
ftp_close($_file[0]);
}
unset($this->_uploading[$_key]);
}
// Cleanup once finished
if (count($this->_uploading) == 0) {
xp_emit($this->_sig_finished);
xp_delete_signal($this);
xp_delete_signal($this->_sig_complete);
xp_delete_signal($this->_sig_failure);
}
});
// Init
xp_emit($this);
}
示例5: 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;
}
示例6: isbusy
function isbusy()
{
$result = false;
do {
if (self::$ret != FTP_MOREDATA) {
break;
}
self::$ret = @ftp_nb_continue(self::$cid);
switch (self::$ret) {
case FTP_MOREDATA:
clearstatcache();
$size = filesize(self::$temp_file);
if (self::$size == $size && ++self::$counts > 10) {
self::$size = 0;
self::$counts = 0;
self::close();
break 2;
}
self::$size = $size;
return true;
case FTP_FINISHED:
self::$size = 0;
self::$counts = 0;
rename(self::$temp_file, self::$local_file);
self::close();
$result = true;
break 2;
default:
// FTP_FAILED
self::$size = 0;
self::$counts = 0;
self::halt("Lost connection to FTP server during query");
break 2;
}
} while (false);
if (self::$fp) {
fclose(self::$fp);
self::$fp = NULL;
}
return $result;
}
示例7: AsynchronouslyContinue
/**
* @return int
*/
public function AsynchronouslyContinue()
{
return ftp_nb_continue($this->getFtp());
}
示例8: nbContinue
/**
* Continues retrieving/sending a file (non-blocking)
* @link http://php.net/ftp_nb_continue
*
* @return integer FTPWrapper::FAILED, FTPWrapper::FINISHED or FTPWrapper::MOREDATA
*/
public function nbContinue()
{
return ftp_nb_continue($this->connection->getStream());
}
示例9: put
/**
* This function will upload a file to the ftp-server. You can either specify a
* absolute path to the remote-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 from which the file will be uploaded 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.
*
* @param string $local_file The local file to upload
* @param string $remote_file The absolute or relative path to the file to
* upload to
* @param bool $overwrite (optional) Whether to overwrite existing file
* @param int $mode (optional) Either FTP_ASCII or FTP_BINARY
* @param int $options (optional) Flags describing the behaviour of this
* function. Currently NET_FTP_BLOCKING and
* NET_FTP_NONBLOCKING are supported, of which
* NET_FTP_NONBLOCKING is the default.
*
* @access public
* @return mixed True on success, otherwise PEAR::Error
* @see NET_FTP_ERR_LOCALFILENOTEXIST,
* NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN,
* NET_FTP_ERR_UPLOADFILE_FAILED, NET_FTP_NONBLOCKING, NET_FTP_BLOCKING
*/
function put($local_file, $remote_file, $overwrite = false, $mode = null, $options = 0)
{
if ($options & (NET_FTP_BLOCKING | NET_FTP_NONBLOCKING) === (NET_FTP_BLOCKING | NET_FTP_NONBLOCKING)) {
return $this->raiseError('Bad options given: NET_FTP_NONBLOCKING and ' . 'NET_FTP_BLOCKING can\'t both be set', NET_FTP_ERR_BADOPTIONS);
}
$usenb = !($options & NET_FTP_BLOCKING == NET_FTP_BLOCKING);
if (!isset($mode)) {
$mode = $this->checkFileExtension($local_file);
}
$remote_file = $this->_constructPath($remote_file);
if (!@file_exists($local_file)) {
return $this->raiseError("Local file '{$local_file}' does not exist.", NET_FTP_ERR_LOCALFILENOTEXIST);
}
if (@ftp_size($this->_handle, $remote_file) != -1 && !$overwrite) {
return $this->raiseError("Remote file '" . $remote_file . "' exists and may not be overwriten.", NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN);
}
if (function_exists('ftp_alloc')) {
ftp_alloc($this->_handle, filesize($local_file));
}
if ($usenb && function_exists('ftp_nb_put')) {
$res = @ftp_nb_put($this->_handle, $remote_file, $local_file, $mode);
while ($res == FTP_MOREDATA) {
$this->_announce('nb_put');
$res = @ftp_nb_continue($this->_handle);
}
} else {
$res = @ftp_put($this->_handle, $remote_file, $local_file, $mode);
}
if (!$res) {
return $this->raiseError("File '{$local_file}' could not be uploaded to '" . $remote_file . "'.", NET_FTP_ERR_UPLOADFILE_FAILED);
} else {
return true;
}
}
示例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_uploading_compile
function ftp_uploading_compile($ftpFolder, $connect_data, $current_file_uri, $current_file_dir)
{
$ftp_connect = @ftp_connect($connect_data['ftp_hostname']);
$ftp_login = @ftp_login($ftp_connect, $connect_data['ftp_username'], $connect_data['ftp_password']);
if (!$ftp_login) {
return false;
} else {
if (substr($ftpFolder, strlen($ftpFolder) - 1) != "/") {
$d = ftp_nb_put($ftp_connect, $ftpFolder . '/archive.zip', $current_file_dir, FTP_BINARY);
} else {
$d = ftp_nb_put($ftp_connect, $ftpFolder . 'archive.zip', $current_file_dir, FTP_BINARY);
}
while ($d == FTP_MOREDATA) {
$d = ftp_nb_continue($ftp_connect);
}
if ($d != FTP_FINISHED) {
exit(1);
}
if (substr($ftpFolder, strlen($ftpFolder) - 1) != "/") {
$d = ftp_nb_put($ftp_connect, $ftpFolder . '/unziper.php', COMPILER_FOLDER . 'unzip.php', FTP_BINARY);
} else {
$d = ftp_nb_put($ftp_connect, $ftpFolder . 'unziper.php', COMPILER_FOLDER . 'unzip.php', FTP_BINARY);
}
while ($d == FTP_MOREDATA) {
$d = ftp_nb_continue($ftp_connect);
}
if ($d != FTP_FINISHED) {
exit(1);
}
if (substr($connect_data['site_url'], strlen($connect_data['site_url']) - 1) != "/") {
$host['unzip'] = $connect_data['site_url'] . '/unziper.php';
$host['dump'] = $connect_data['site_url'] . '/db_upload.php';
} else {
$host['unzip'] = $connect_data['site_url'] . 'unziper.php';
$host['dump'] = $connect_data['site_url'] . 'db_upload.php';
}
$host['link'] = $connect_data['site_url'];
// close connection
ftp_close($ftp_connect);
echo json_encode($host);
return true;
}
}
示例12: get_htaccess
function get_htaccess($ftp_handle, $dir)
{
$local_htaccess = tempnam("files", "down");
$ftp_htaccess = str_replace("//", "/", $dir . '/.htaccess');
$ret = @ftp_nb_get($ftp_handle, $local_htaccess, $ftp_htaccess, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
// Продолжаем загрузку
$ret = @ftp_nb_continue($ftp_handle);
}
@chmod($local_htaccess, 0644);
$content = @file_get_contents($local_htaccess);
@unlink($local_htaccess);
return $content;
}
示例13: 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");
示例14: put
public function put($local_file, $remote_file, $overwrite = false, $mode = null, $options = 0)
{
if ($options & (FILE_FTP_BLOCKING | FILE_FTP_NONBLOCKING) === (FILE_FTP_BLOCKING | FILE_FTP_NONBLOCKING)) {
throw new FTPException("Bad options given: FILE_FTP_NONBLOCKING and '. 'FILE_FTP_BLOCKING can't both be set");
}
$usenb = !($options & FILE_FTP_BLOCKING == FILE_FTP_BLOCKING);
if (!isset($mode)) {
$mode = $this->checkFileExtension($local_file);
}
$remote_file = $this->constructPath($remote_file);
if (!file_exists($local_file)) {
throw new FTPException("Local file '{$local_file}' does not exist.");
}
if (ftp_size($this->handle, $remote_file) != -1 && !$overwrite) {
throw new FTPException("Remote file '" . $remote_file . "' exists and may not be overwriten.");
}
if (function_exists('ftp_alloc')) {
ftp_alloc($this->handle, filesize($local_file));
}
if ($usenb && function_exists('ftp_nb_put')) {
$res = ftp_nb_put($this->handle, $remote_file, $local_file, $mode);
while ($res == FTP_MOREDATA) {
$res = ftp_nb_continue($this->handle);
}
} else {
$res = ftp_put($this->handle, $remote_file, $local_file, $mode);
}
if (!$res) {
throw new FTPException("File '{$local_file}' could not be uploaded to '" . $remote_file . "'.");
}
return true;
}
示例15: 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;
}