Hàm ftp_nb_fget () tải xuống một tệp từ máy chủ FTP và lưu nó vào một tệp đang mở.
Cú pháp
ftp_nb_fget(con,open_file,server_file,transfer_mode,beg_pos);
Tham số
-
con - Kết nối FTP
-
open_file - Dữ liệu cục bộ được lưu trữ tại đây.
-
server_file - Tệp máy chủ để tải xuống.
-
transfer_mode - Đây là chế độ chuyển khoản. Sau đây là các giá trị có thể có:
- FTP_ASCII hoặc
- FTP_BINARY
-
please_pos - Vị trí bắt đầu tải xuống
Quay lại
Hàm ftp_nb_fget () trả về bất kỳ giá trị nào sau đây -
-
FTP_FAILED - gửi / nhận không thành công
-
FTP_FINISHED - gửi / nhận đã hoàn thành
-
FTP_MOREDATA - đang tiến hành gửi / nhận
Ví dụ
Sau đây là một ví dụ -
<?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";
$file_pointer = fopen($local_file,"w");
$c = ftp_nb_fget($con, $file_pointer , $my_serverfile, FTP_BINARY)
while ($c == FTP_MOREDATA){
// continue downloading
$c = ftp_nb_continue($con);
}
if ($c != FTP_FINISHED){
echo "Error downloading the server file!";
exit(1);
}
// close
ftp_close($con);
fclose($file_pointer )
?>