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, 22 Aug 2008

view this page in

ftp_nb_fget

(PHP 4 >= 4.3.0, PHP 5)

ftp_nb_fgetRecupera un archivo desde el servidor FTP y lo escribe sobre un archivo abierto (modo no-bloqueo)

Descripción

int ftp_nb_fget ( resource $secuencia_ftp , resource $gestor , string $archivo_remoto , int $modo [, int $pos_continuacion ] )

ftp_nb_fget() recupera un archivo remoto desde el servidor FTP.

La diferencia entre esta función y ftp_fget() es que la presente función recupera el archivo de forma asincrónica, así que su programa puede realizar otras operaciones mientras que el archivo está siendo descargado.

Lista de parámetros

secuencia_ftp

El identificador de enlace de la conexión FTP.

gestor

Un apuntador de archivo abierto en el cual almacenar los datos.

archivo_remoto

La ruta del archivo remoto.

modo

El modo de transferencia. Debe ser FTP_ASCII o FTP_BINARY.

pos_continuacion

Valores retornados

Devuelve FTP_FAILED o FTP_FINISHED o FTP_MOREDATA.

Ejemplos

Example #1 Ejemplo de ftp_nb_fget()

<?php

// abrir un archivo para lectura
$archivo 'index.php';
$da fopen($archivo'w');

$id_con ftp_connect($servidor_ftp);

$resultado_login ftp_login($id_con$nombre_usuario_ftp$contrasenya_ftp);

// Iniciar la descarga
$ret ftp_nb_fget($id_con$da$archivoFTP_BINARY);
while (
$ret == FTP_MOREDATA) {

   
// Haga lo que desee
   
echo ".";

   
// Continuar la descarga...
   
$ret ftp_nb_continue($id_con);
}
if (
$ret != FTP_FINISHED) {
   echo 
"Hubo un error en la descarga del archivo...";
   exit(
1);
}

// cerrar el apuntador de archivo
fclose($da);
?>



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, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites