ftp_nb_get() 函数在 PHP 中


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){
      // continue downloading
      $c = ftp_nb_continue($con);
   }
   if ($c != FTP_FINISHED) {
      echo "Error downloading the server file!";
      exit(1);
   }
   // close
   fclose($file_pointer)
?>

更新于: 2019 年 7 月 30 日

56 次浏览

开始你的 职业生涯

完成课程获得认证

开始吧
广告
© . All rights reserved.