If you want to monitor the progress of the download, you may use the filesize()-Function.
But note: The results of said function are cached, so you'll always get 0 bytes. Call clearstatcache() before calling filesize() to determine the actual size of the downloaded file.
This may have performance implications, but if you want to provide the information, there's no way around it.
Above sample extended:
<?php
$fs = ftp_size($my_connection, "test");
$ret = ftp_nb_get($my_connection, "test", "README", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
clearstatcache(); $dld = filesize($locfile);
if ( $dld > 0 ){
$i = ($dld/$fs)*100;
printf("\r\t%d%% downloaded", $i);
}
$ret = ftp_nb_continue ($my_connection);
}
if ($ret != FTP_FINISHED) {
echo "There was an error downloading the file...";
exit(1);
}
?>
Philip