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

Hàm ftp_get() trong PHP


Hàm ftp_get() (thường dùng qua ftp_fget()) tải xuống tập tin từ máy chủ FTP và lưu vào tập tin cục bộ.

Cú pháp

ftp_fget($conn, $local_file, $server_file, $mode, $startpos)

Tham số

  • conn – Kết nối FTP.

  • local_file – Tập tin cục bộ lưu dữ liệu.

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

  • mode – Chế độ truyền.

  • startpos – Vị trí bắt đầu tải xuống (từ PHP 4.3.0).

Giá trị trả về

Hàm trả về TRUE nếu thành công, FALSE nếu thất bại.

Ví dụ

<?php
$ftp_server = "192.168.0.4";
$ftp_user = "amit";
$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";
$my_file = "new.txt";
if (ftp_fget($con, $my_file, $my_serverfile, FTP_ASCII, 0)) {
    echo "Written to local file!";
} else {
    echo "Error in downloading the server file!";
}
ftp_close($con);
fclose($file_pointer);
?>