Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm ftp_nb_get() trong PHP


Hàm ftp_nb_get() tải xuống (download) tập tin từ máy chủ FTP theo chế độ không chặn (non-blocking).

Cú pháp

ftp_nb_get($conn, $local_file, $server_file, $transfer_mode, $beg_pos)

Tham số

  • conn – Kết nối FTP.

  • local_file – Đường dẫn tập tin cục bộ.

  • server_file – Tập tin trên server cần tải xuống.

  • transfer_mode – Chế độ truyền: FTP_ASCII hoặc FTP_BINARY.

  • beg_pos – Vị trí bắt đầu tải xuống.

Giá trị trả về

Hàm trả về một trong các giá trị:

  • FTP_FAILED – Gửi/nhận thất bại.
  • FTP_FINISHED – Gửi/nhận hoàn tất.
  • FTP_MOREDATA – Đang gửi/nhận.

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";
$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);
}
fclose($file_pointer);
?>