PHP ftp_nb_continue() Function
The PHP ftp_nb_continue() function continues retrieving/sending a file non-blocking to the FTP server.
Syntax
ftp_nb_continue(ftp)
Parameters
ftp |
Required. Specify the FTP connection to use. |
Return Value
Returns any of the following values:
- FTP_FAILED: Asynchronous transfer has failed.
- FTP_FINISHED: Asynchronous transfer has finished.
- FTP_MOREDATA: Asynchronous transfer is still active.
Example:
The example below shows the usage of ftp_nb_continue() function.
<?php //FTP server to use $ftp_server = "ftp.example.com"; //username for the FTP Connection $ftp_user = "user"; //password for the user $ftp_pass = "password"; //set up a connection or die $ftp = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); if($ftp) { echo "Successfully connected to $ftp_server!\n"; //trying to login if(@ftp_login($ftp, $ftp_user, $ftp_pass)) { echo "Connected as $ftp_user@$ftp_server\n"; //initiating the download $ret = ftp_nb_continue($ftp, "local_demo.txt", "server_demo.txt", FTP_ASCII); while ($ret == FTP_MOREDATA) { //continue downloading... $ret = ftp_nb_continue($ftp); } if ($ret == FTP_FINISHED) { echo "Successfully downloaded the file\n"; } else { echo "Error while downloading the file\n"; exit(1); } } else { echo "Couldn't connect as $ftp_user\n"; } //close the connection if(ftp_close($ftp)) { echo "Connection closed successfully!\n"; } } ?>
The output of the above code will be:
Successfully connected to ftp.example.com! Connected as user@ftp.example.com Successfully downloaded the file Connection closed successfully!
❮ PHP FTP Reference