In PHP, ftp_nb_fget() starts a non-blocking download of a remote file and writes it into an open file pointer (a stream) that you provide.
It works like ftp_fget(), but it does not wait for the whole download to finish. It returns after the first chunk, and you call ftp_nb_continue() to receive the rest. This is useful for large files or when you want to show progress.
Syntax
Call ftp_nb_fget() with the values you need. Start with this line.
Resumes a download starting at byte 1024 of the remote file.
It returns FTP_MOREDATA, FTP_FINISHED or FTP_FAILED. If the status is FTP_MOREDATA, call ftp_nb_continue() until the transfer finishes. Open the local stream with fopen() in write mode first, and close it with fclose() afterwards.
Library declarations
PHP
ftp_nb_fget(FTP\Connection $ftp, resource $stream, 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().
stream
Required. An open file pointer where the downloaded data is written.
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 Into an Open Stream
Open a local file, start the download and finish it with ftp_nb_continue().