PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ftp_nb_fput> <ftp_nb_continue
Last updated: Fri, 10 Oct 2008

view this page in

ftp_nb_fget

(PHP 4 >= 4.3.0, PHP 5)

ftp_nb_fgetСкачивает файл с FTP сервера в асинхронном режиме и сохраняет его в предварительно открытом файле

Описание

int ftp_nb_fget ( resource $ftp_stream , resource $handle , string $remote_file , int $mode [, int $resumepos ] )

ftp_nb_fget() скачивает удалённый файл с FTP сервера.

Разница между этой функцией и ftp_fget() заключается в том, что эта функция получает файл асинхронно, так что ваша программа может совершать другие операции, пока файл скачивается.

Список параметров

ftp_stream

Идентификатор соединения с FTP сервером

handle

Открытый файловый дескриптор для сохранения данных.

remote_file

Путь к удалённому файлу.

mode

Режим передачи. Должен быть либо FTP_ASCII, либо FTP_BINARY.

resumepos

Возвращаемые значения

Возвращает FTP_FAILED, FTP_FINISHED или FTP_MOREDATA.

Примеры

Пример #1 Пример использования ftp_nb_fget()

<?php

// открыть файл для записи
$file 'index.php';
$fp fopen($file'w');

$conn_id ftp_connect($ftp_server);

$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// Начало скачивания
$ret ftp_nb_fget($conn_id$fp$fileFTP_BINARY);
while (
$ret == FTP_MOREDATA) {

   
// производим какие-то дествия ...
   
echo ".";

   
// продолжение скачивания ...
   
$ret ftp_nb_continue($conn_id);
}
if (
$ret != FTP_FINISHED) {
   echo 
"При скачивании файла произолшла ошибка...";
   exit(
1);
}

// закрытие файла
fclose($fp);
?>

Смотрите также



add a note add a note User Contributed Notes
ftp_nb_fget
pilif at pilif dot ch
16-Nov-2004 02:53
If you want to monitor the progress of the download, you may use the filesize()-Function.

But note: The results of said function are cached, so you'll always get 0 bytes. Call clearstatcache() before calling filesize() to determine the actual size of the downloaded file.

This may have performance implications, but if you want to provide the information, there's no way around it.

Above sample extended:

<?php
// get the size of the remote file
$fs = ftp_size($my_connection, "test");

// Initate the download
$ret = ftp_nb_get($my_connection, "test", "README", FTP_BINARY);
while (
$ret == FTP_MOREDATA) {
  
  
clearstatcache(); // <- this is important
  
$dld = filesize($locfile);
   if (
$dld > 0 ){
      
// calculate percentage
      
$i = ($dld/$fs)*100;
      
printf("\r\t%d%% downloaded", $i);
   }  

  
// Continue downloading...
  
$ret = ftp_nb_continue ($my_connection);
}
if (
$ret != FTP_FINISHED) {
   echo
"There was an error downloading the file...";
   exit(
1);
}
?>

Philip

ftp_nb_fput> <ftp_nb_continue
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites