PHP 中的 ftp_nb_get() 函数

phpserver side programmingprogramming更新于 2025/5/26 3:07:17

ftp_nb_get() 函数从 FTP 服务器下载文件。

语法

ftp_nb_get(con,local_file,server_file,transfer_mode,beg_pos);

参数

  • con − FTP 连接

  • local_file − 本地文件路径

  • server_file − 要下载的服务器文件

  • transfer_mode − 这是传输模式。以下是可能的值 −

    - FTP_ASCII,或

    - FTP_BINARY

  • beg_pos − 开始下载的位置

返回

ftp_nb_get() 函数返回以下任意值 −

  • FTP_FAILED − 发送/接收失败

  • FTP_FINISHED − 发送/接收完成

  • FTP_MOREDATA − 发送/接收正在进行中

示例

以下是示例:

<?php
   $ftp_server = "192.168.0.4";
   $ftp_user = "jacob";
   $ftp_pass = "tywg61gh";
   $con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
   $login = ftp_login($con, $ftp_user, $ftp_pass);
   $my_serverfile = "demo.txt";
   $local_file = "new.txt";
   $c = ftp_nb_get($con, $local_file , $my_serverfile, FTP_ASCII)
   while ($c == FTP_MOREDATA){
      // 继续下载
      $c = ftp_nb_continue($con);
   }
   if ($c != FTP_FINISHED) {
      echo "Error downloading the server file!";
      exit(1);
   }
   // close
   fclose($file_pointer)
?>

相关文章