PHP.nl

ftp_nb_get

ftp_nb_get

Retrieves a file from the FTP server and writes it to a local file (non-blocking)

 **ftp_nb_get** FTP\Connection $ftp string $local_filename string $remote_filename int $mode int $offset
retrieves a remote file from the FTP server,

and saves it into a local file. ftp_nb_get

The difference between this function and is that this function retrieves the file asynchronously, so your program can perform other operations while the file is being downloaded. ftp_get

ftp``local_filenameThe local file path (will be overwritten if the file already exists).

remote_filenameThe remote file path.

mode The transfer mode. Must be either or . FTP_ASCII``FTP_BINARY

offsetThe position in the remote file to start downloading from.

Returns or or , or false on failure to open the local file. FTP_FAILED``FTP_FINISHED``FTP_MOREDATA

Voorbeeld: example

<?php

// Initiate the download
$ret = ftp_nb_get($ftp, "test", "README", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
   
   // Do whatever you want
   echo ".";

   // Continue downloading...
   $ret = ftp_nb_continue($ftp);
}
if ($ret != FTP_FINISHED) {
   echo "There was an error downloading the file...";
   exit(1);
}
?>

**Voorbeeld: Resuming a download with **

<?php

// Initiate 
$ret = ftp_nb_get($ftp, "test", "README", FTP_BINARY, 
                      filesize("test"));
// OR: $ret = ftp_nb_get($ftp, "test", "README", 
//                           FTP_BINARY, FTP_AUTORESUME);
while ($ret == FTP_MOREDATA) {
   
   // Do whatever you want
   echo ".";

   // Continue downloading...
   $ret = ftp_nb_continue($ftp);
}
if ($ret != FTP_FINISHED) {
   echo "There was an error downloading the file...";
   exit(1);
}
?>

**Voorbeeld: Resuming a download at position 100 to a new file with **

<?php

// Disable Autoseek
ftp_set_option($ftp, FTP_AUTOSEEK, false);

// Initiate
$ret = ftp_nb_get($ftp, "newfile", "README", FTP_BINARY, 100);
while ($ret == FTP_MOREDATA) {

   /* ... */
   
   // Continue downloading...
   $ret = ftp_nb_continue($ftp);
}
?>

In the example above, is 100 bytes smaller than on the FTP server because we started reading at offset 100. If we didn't disable , the first 100 bytes of would be . FTP_AUTOSEEK``'\0'

ftp_nb_fget``ftp_nb_continue``ftp_fget``ftp_get