ftp_nb_fput

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

ftp_nb_fputGrava um arquivo a partir de um arquivo aberto no servidor FTP (sem bloquear)

Descrição

ftp_nb_fput ( resource $ftp_stream , string $remote_file , resource $handle , int $mode , int $startpos = ? ) : int

ftp_nb_fput() envia os dados do ponteiro de arquivo para o arquivo remoto no servidor FTP.

A diferença entra esta função e ftp_fput() é que esta função envia o arquivo de forma assimcronoma, assim o seu programa pode realizar outras operações enquanto o arquivo esta sendo carregado.

Parâmetros

ftp_stream

O identificador da conexão FTP.

remote_file

O caminho para o arquivo remoto.

handle

Um ponteiro de arquivo aberto para o arquivo local. A leitura termina ao finbal do arquivo.

mode

O modo de transferência. Deve ser FTP_ASCII ou FTP_BINARY.

startpos

Valor Retornado

Retorna FTP_FAILED ou FTP_FINISHED ou FTP_MOREDATA.

Exemplos

Exemplo #1 Exemplo ftp_nb_fput()

<?php

$file 
'index.php';

$fp fopen($file'r');

$conn_id ftp_connect($ftp_server);

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

// Initate the upload
$ret ftp_nb_fput($conn_id$file$fpFTP_BINARY);
while (
$ret == FTP_MOREDATA) {

   
// Do whatever you want
   
echo ".";

   
// Continue upload...
   
$ret ftp_nb_continue($conn_id);
}
if (
$ret != FTP_FINISHED) {
   echo 
"There was an error uploading the file...";
   exit(
1);
}

fclose($fp);
?>

Veja Também

  • ftp_nb_put() - Grava um arquivo no servidor FTP (sem bloquear)
  • ftp_nb_continue() - Continua a receber/enviar um arquivo (sem bloquear)
  • ftp_put() - Envia um arquivo para o servidor FTP
  • ftp_fput() - Envia um arquivo aberto para um servidor php

add a note add a note

User Contributed Notes 2 notes

up
2
jascha at bluestatedigital dot com
19 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
-2
marcopardo at gmx dot de
4 years ago
FTP_FAILED = 0
FTP_FINISHED = 1
FTP_MOREDATA = 2
To Top