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 "下载服务器文件时出错!"; exit(1); } //关闭 fclose($file_pointer) ?>