In PHP, ftp_nb_put() starts a non-blocking upload of a local file to an FTP server. The local file is given by its name, so you do not need to open it yourself.
It is the non-blocking version of ftp_put(). It sends the first chunk and returns, then you call ftp_nb_continue() until the upload ends. Your script stays free to do other work or show progress during large uploads.
Syntax
Call ftp_nb_put() with the values you need. Start with this line.
Resumes an upload starting at byte 8192 of the remote file.
Mind the argument order: the remote name comes first, then the local name. It returns FTP_MOREDATA, FTP_FINISHED or FTP_FAILED, so keep calling ftp_nb_continue() while the result is FTP_MOREDATA.
Library declarations
PHP
ftp_nb_put(FTP\Connection $ftp, string $remote_filename, string $local_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().
remote_filename
Required. The path where the file is stored on the FTP server.
local_filename
Required. The path of the local file that you want to upload.
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 upload starts. The default is 0.
Return Value
Return Value
Description
int
FTP_MOREDATA if the upload is still running, FTP_FINISHED when it is done, or FTP_FAILED on error.
PHP Examples
Example 1 — Upload a File in Chunks
Start a non-blocking upload and loop until the server has received everything.