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

search for in the

ftp_nlist> <ftp_nb_get
Last updated: Thu, 17 Sep 2009

view this page in

ftp_nb_put

(PHP 4 >= 4.3.0, PHP 5)

ftp_nb_putAlmacena un archivo en el servidor FTP (modo no-bloqueo)

Descripción

int ftp_nb_put ( resource $secuencia_ftp , string $archivo_remoto , string $archivo_local , int $modo [, int $pos_comienzo ] )

ftp_nb_put() almacena un archivo local en el servidor FTP.

La diferencia entre ésta función y ftp_put() es que ésta carga el archivo asincrónicamente, de modo que su programa puede realizar otras operaciones mientras el archivo está siendo cargado.

Lista de parámetros

secuencia_ftp

El identificador de enlace de la conexión FTP.

archivo_remoto

La ruta del archivo remoto.

archivo_local

La ruta del archivo local.

modo

El modo de transferencia. Debe ser FTP_ASCII o FTP_BINARY.

pos_comienzo

Valores retornados

Devuelve FTP_FAILED o FTP_FINISHED o FTP_MOREDATA.

Ejemplos

Example #1 Ejemplo de ftp_nb_put()

<?php

// Iniciar la carga
$ret ftp_nb_put($mi_conexion"test.remoto""test.local"FTP_BINARY);
while (
$ret == FTP_MOREDATA) {

   
// Haga lo que quiera
   
echo ".";

   
// Continuar la carga...
   
$ret ftp_nb_continue($mi_conexion);
}
if (
$ret != FTP_FINISHED) {
   echo 
"Hubo un error cargando el archivo...";
   exit(
1);
}
?>

Example #2 Reanudando una carga con ftp_nb_put()

<?php

// Iniciar
$ret ftp_nb_put($mi_conexion"test.remoto""test.local",
                  
FTP_BINARYftp_size("test.remoto"));

// O: $ret = ftp_nb_put($mi_conexion, "test.remoto", "test.local",
//                      FTP_BINARY, FTP_AUTORESUME);

while ($ret == FTP_MOREDATA) {

   
// Haga lo que quiera
   
echo ".";

   
// Continuar la carga...
   
$ret ftp_nb_continue($mi_conexion);
}
if (
$ret != FTP_FINISHED) {
   echo 
"Hubo un error cargando el archivo...";
   exit(
1);
}
?>

Ver también

  • ftp_nb_fput() - Almacena un archivo desde un archivo abierto en el servidor FTP (modo no-bloqueo)
  • ftp_nb_continue() - Continúa recuperando/enviando un archivo (modo no-bloqueo)
  • ftp_put() - Carga un archivo al servidor FTP
  • ftp_fput() - Carga un archivo abierto al servidor FTP



ftp_nlist> <ftp_nb_get
Last updated: Thu, 17 Sep 2009
 
add a note add a note User Contributed Notes
ftp_nb_put
WebSee.ru
11-Aug-2009 01:01
How to realize the possibility of transferring data from one FTP-server to another via FXP:

<?php
// ...

$ansver = ftp_raw($ftp_conn1, 'PASV');

if (
intval($ansver[0]) == 227) {
   
ftp_raw($ftp_conn2, 'PORT '.substr($ansver[0], $n = strpos($ansver[0], '(') + 1, strpos($m[0], ')', $n) - $n));
   
ftp_raw($ftp_conn1, 'STOR '.$filename); // need asynchronously (non-blocking)
   
ftp_raw($ftp_conn2, 'RETR '.$filename);
}
?>
kaiohken1982 at hotmail dot com
29-Nov-2006 12:53
Hi,
I tried to use both ftp_put() and ftp_nb_put() adding the
variable $start = date("Y:m:d h:i:s"); at the begin of the script and the variable $end = date("Y:m:d h:i:s"); at its end, after the file upload function.
With the gprs connection I'm now using and trying to upload a .jpg file of 67,5 kb the time difference between $start and $end was 40 seconds in both cases, so I can suppose that there is no difference between these upload function.
The difference comes if you put anything inside the while ($ftp_upload == FTP_MOREDATA) loop.
I hope this note can help.
Regards
Ariel asphp at dsgml dot com
12-Jul-2006 07:11
Don't add a sleep() inside the loop. If you do you will severely slow down the upload.

In my tests, each time through the loop it send about 2.5K, looping about 220 times per second. (Which is very little.)

You won't necessarily get the same numbers as me per loop, but clearly PHP does it's own management of the loop so that you don't consume all the CPU on the server.
brandon dot farber at gmail dot com
01-Feb-2006 11:14
I couldn't see this noted anywhere...

ftp_nb_put apparently takes a much much longer time to upload the file than ftp_put (I haven't done any packet sniffing or logging tests to find out why).  I was using a script, nearly identical to the example above, and a 100KB file had only uploaded 3.99KB after about 8 minutes!  The php script naturally timed out before it was complete.

I changed my function to use ftp_put, got rid of the loop to check FTP_MOREDATA (as you will see in the example above), and the same script uploaded 2.2MB within 30 seconds with no other changes.

If you're using this function instead of ftp_put *purely to try to speed up your script* and it's taking a long time, you might want to try ftp_put instead.
ted at hostleft dot com
11-Jan-2005 09:13
If you receive an error like: 

Warning:  ftp_nb_put(): Unable to service PORT commands in /path/to/file.php on line 27

verify whether you need to be in PASV mode. You can go into PASV mode by declaring

>  ftp_pasv($cnx,TRUE);
manu at manux dot org
07-Jan-2005 07:35
When using non blocking functions if you try to disconnect while your non blocking operation is in progress the disconnect command will not work until the operation is not finished.

ftp_nlist> <ftp_nb_get
Last updated: Thu, 17 Sep 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites