ftp_nb_get
(PHP 4 >= 4.3.0, PHP 5)
ftp_nb_get -- Obtém um arquivo do servidor FTP e escreve-o em um arquivo local (sem bloquear)
Descrição
int
ftp_nb_get ( resource ftp_stream, string local_file, string remote_file, int mode [, int resumepos] )
ftp_nb_get() obtém um arquivo remoto do servidor FTP e salva-o
em um arquivo local.
A diferença entre esta função é ftp_get() é que
esta função obtém o arquivo de forma assincronoma, assim o seu programa pode
realizar outras operações enquanto o arquivo esta sendo baixado.
Parâmetros
ftp_stream
O identificador com a conexão FTP.
local_file
O caminho para o arquivo local (será sobrescrito se o arquivo local já existir).
remote_file
O caminho para o arquivo remoto.
mode
O modo de transferência. Deve ser FTP_ASCII ou
FTP_BINARY.
resumepos
Valores de retornado
Retorna FTP_FAILED ou FTP_FINISHED
ou FTP_MOREDATA.
Exemplos
Exemplo 1. Exemplo ftp_nb_get()
<?php
// Initate the download $ret = ftp_nb_get($my_connection, "test", "README", FTP_BINARY); while ($ret == FTP_MOREDATA) { // Do whatever you want echo ".";
// Continue downloading... $ret = ftp_nb_continue($my_connection); } if ($ret != FTP_FINISHED) { echo "There was an error downloading the file..."; exit(1); } ?>
|
|
Exemplo 2. Continuando um download com ftp_nb_get()
<?php
// Initate $ret = ftp_nb_get($my_connection, "test", "README", FTP_BINARY, filesize("test")); // OR: $ret = ftp_nb_get($my_connection, "test", "README", // FTP_BINARY, FTP_AUTORESUME); while ($ret == FTP_MOREDATA) { // Do whatever you want echo ".";
// Continue downloading... $ret = ftp_nb_continue($my_connection); } if ($ret != FTP_FINISHED) { echo "There was an error downloading the file..."; exit(1); } ?>
|
|
Exemplo 3.
Continuando um download na posição 100 para um
novo arquivo com ftp_nb_get()
<?php
// Disable Autoseek ftp_set_option($my_connection, FTP_AUTOSEEK, false);
// Initiate $ret = ftp_nb_get($my_connection, "newfile", "README", FTP_BINARY, 100); while ($ret == FTP_MOREDATA) {
/* ... */ // Continue downloading... $ret = ftp_nb_continue($my_connection); } ?>
|
|
No exemplo acima, newfile é 100 bytes menor
do que README no servidor FTP porque nós começamos a
ler a partir da posição 100. Se nós não disabilitarmos
FTP_AUTOSEEK, os primeiros 100 bytes de
newfile serão '\0'.