In PHP, ftp_nb_get() starts a non-blocking download of a remote file and saves it to a local file name that you choose.
Unlike ftp_get(), which waits until the whole file arrives, ftp_nb_get() returns after the first chunk. You then call ftp_nb_continue() in a loop to get the rest. That makes it a good choice for large files or progress messages.
Syntax
Call ftp_nb_get() with the values you need. Start with this line.
Resumes the download from byte 4096 of the remote file.
It returns FTP_MOREDATA, FTP_FINISHED or FTP_FAILED. When you get FTP_MOREDATA, call ftp_nb_continue() until the transfer ends. PHP opens and writes the local file for you.
Library declarations
PHP
ftp_nb_get(FTP\Connection $ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): int
Parameters
Parameter
Description
ftp
Required. The FTP\Connection object returned by ftp_connect() or ftp_ssl_connect().
local_filename
Required. The path of the local file where the data is saved. An existing file is overwritten.
remote_filename
Required. The path of the file on the FTP server.
mode
Optional. The transfer mode, FTP_ASCII or FTP_BINARY. The default is FTP_BINARY.
offset
Optional. The position in the remote file where the download starts. The default is 0.
Return Value
Return Value
Description
int
FTP_MOREDATA if the transfer is still running, FTP_FINISHED when it is done, or FTP_FAILED on error.
PHP Examples
Example 1 — Download a File in Chunks
Start a non-blocking download and loop until the transfer is finished.