ftp_nb_fput

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

ftp_nb_fputEscribe un fichero en un servidor FTP, y lo lee desde un fichero (no bloqueante)

Descripción

ftp_nb_fput(
    FTP\Connection $ftp,
    string $remote_filename,
    resource $stream,
    int $mode = FTP_BINARY,
    int $offset = 0
): int

ftp_nb_fput() escribe el fichero remote_filename presente en la máquina local, en el servidor FTP ftp.

La diferencia entre esta función y ftp_fput() es que esta función puede leer el fichero de manera asíncrona, para que su programa realice otras tareas mientras el fichero se descarga.

Parámetros

ftp

An FTP\Connection instance.

remote_filename

La ruta hacia el fichero remoto.

stream

Un puntero de fichero hacia un fichero local. La lectura se detiene al final del fichero.

mode

El modo de transferencia. Debe ser FTP_ASCII o FTP_BINARY.

offset

La posición en el fichero remoto desde la cual comenzará la descarga.

Valores devueltos

Devuelve FTP_FAILED, FTP_FINISHED o FTP_MOREDATA.

Historial de cambios

Versión Descripción
8.1.0 The ftp parameter expects an FTP\Connection instance now; previously, a recurso was expected.
7.3.0 El argumento mode ahora es opcional. Anteriormente era obligatorio.

Ejemplos

Ejemplo #1 Ejemplo con ftp_nb_fput()

<?php

$file
= 'index.php';

$fp = fopen($file, 'r');

$ftp = ftp_connect($ftp_server);

$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// Inicia la subida
$ret = ftp_nb_fput($ftp, $file, $fp, FTP_BINARY);
while (
$ret == FTP_MOREDATA) {

// Realice lo que desee...
echo ".";

// Continúa la subida...
$ret = ftp_nb_continue($ftp);
}
if (
$ret != FTP_FINISHED) {
echo
"Ocurrió un problema durante la subida del fichero...";
exit(
1);
}

fclose($fp);
?>

Ver también

add a note

User Contributed Notes 2 notes

up
1
jascha at bluestatedigital dot com
20 years ago
There is an easy way to check progress while uploading a file. Just use the ftell function to watch the position in the file handle. ftp_nb_fput will increment the position as the file is transferred.

Example:

<?

$fh
= fopen ($file_name, "r");
$ret = ftp_nb_fput ($ftp, $file_name, $fh, FTP_BINARY);
while (
$ret == FTP_MOREDATA) {
print
ftell ($fh)."\n";
$ret = ftp_nb_continue($ftp);
}
if (
$ret != FTP_FINISHED) {
print (
"error uploading\n");
exit(
1);
}
fclose($fh);

?>

This will print out the number of bytes transferred thus far, every time the loop runs. Coverting this into a percentage is simply a matter of dividing the number of bytes transferred by the total size of the file.
up
-3
marcopardo at gmx dot de
5 years ago
FTP_FAILED = 0
FTP_FINISHED = 1
FTP_MOREDATA = 2
To Top