PHP ftp_nb_continue() 函数

定义和用法

ftp_nb_continue() 函数连续获取 / 发送文件。

该函数返回下列值:

  • FTP_FAILED (send/receive failed)
  • FTP_FINISHED (send/receive completed)
  • FTP_MOREDATA (send/receive in progress)

该函数异步地发送/获取文件。这意味着您的程序可以在文件下载时执行其他操作。

语法

  1. ftp_nb_continue(ftp_connection)
参数 描述
ftp_connection 必需。规定要使用的 FTP 连接(FTP 连接的标识符)。

例子

  1. <?php
  2. $source = "source.txt";
  3. $target = fopen("target.txt", "w");
  4.  
  5. $conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
  6. ftp_login($conn,"admin","ert456");
  7.  
  8. $status = ftp_nb_fget($conn,$source,$target,FTP_ASCII);
  9.  
  10. while ($status == FTP_MOREDATA)
  11. {
  12. $status = ftp_nb_continue($conn);
  13. }
  14.  
  15. if ($status != FTP_FINISHED)
  16. {
  17. echo "Download error";
  18. }
  19.  
  20. ftp_close($conn);
  21. ?>