In PHP, ftp_nb_fput() starts a non-blocking upload of data from an open file pointer (a stream) to a file on the FTP server.
It is the non-blocking version of ftp_fput(). It uploads the first chunk and returns right away, then you call ftp_nb_continue() until the upload is done. This keeps your script responsive during big uploads.
Syntax
Call ftp_nb_fput() with the values you need. Start with this line.
Resumes an upload from byte 2048 of the remote file.
Open the local file with fopen() in read mode first. The function returns FTP_MOREDATA, FTP_FINISHED or FTP_FAILED. Keep calling ftp_nb_continue() while the status is FTP_MOREDATA.
Library declarations
PHP
ftp_nb_fput(FTP\Connection $ftp, string $remote_filename, resource $stream, 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 of the file to create on the FTP server.
stream
Required. An open file pointer. PHP reads from it until the end of the file.
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 From an Open Stream
Open a local file, start the upload and finish it with ftp_nb_continue().