Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
ftp_nb_continue() function in PHP
The ftp_nb_continue() function continues to receive or send a file to the FTP server in non-blocking mode. This function is used with non-blocking FTP operations to check the status and continue the transfer process.
Syntax
ftp_nb_continue($ftp_connection);
Parameters
ftp_connection − The FTP connection resource created by
ftp_connect().
Return Value
The ftp_nb_continue() function returns one of the following constants −
FTP_FAILED − The transfer failed
FTP_FINISHED − The transfer completed successfully
FTP_MOREDATA − The transfer is still in progress
Example
The following example shows how to use ftp_nb_continue() with ftp_nb_get() to download a file in non-blocking mode. Here, "local_file.txt" is the local destination file, and "remote_file.txt" is the file on the FTP server −
<?php
// Establish FTP connection
$ftp_conn = ftp_connect("ftp.example.com");
ftp_login($ftp_conn, "username", "password");
// Start non-blocking download
$result = ftp_nb_get($ftp_conn, "local_file.txt", "remote_file.txt", FTP_BINARY);
while ($result == FTP_MOREDATA) {
// Download continues
echo "File is downloading...<br>";
$result = ftp_nb_continue($ftp_conn);
}
if ($result != FTP_FINISHED) {
echo "Download failed!<br>";
exit(1);
} else {
echo "Download completed successfully!<br>";
}
ftp_close($ftp_conn);
?>
File is downloading... File is downloading... Download completed successfully!
Key Points
This function only works with non-blocking FTP operations like
ftp_nb_get()andftp_nb_put()Use it in a loop to continuously check the transfer status
Always check the return value to determine if the transfer completed, failed, or needs to continue
Conclusion
The ftp_nb_continue() function is essential for managing non-blocking FTP transfers, allowing you to monitor progress and handle large file transfers efficiently without blocking script execution.
