從 FTP 伺服器上下載一個檔案

ftp_get

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_get從 FTP 伺服器上下載一個檔案

說明

ftp_get(
    resource $ftp_stream,
    string $local_file,
    string $remote_file,
    int $mode,
    int $resumepos = 0
): bool

ftp_get() 函式用來下載 FTP 伺服器上指定的檔案並儲存為本地檔案。

參數

ftp_stream

FTP 連線的鏈接識別符號。

local_file

檔案本地的路徑(如果檔案已經存在,則會被覆蓋)。

remote_file

檔案的遠端路徑。

mode

傳送模式。只能為 (文字模式) FTP_ASCII 或 (二進制模式) FTP_BINARY 中的其中一個。

resumepos

從遠端檔案的這個位置繼續下載。

返回值

成功時返回 true, 或者在失敗時返回 false

範例

示例 #1 ftp_get() 例子

<?php

// define some variables
$local_file 'local.zip';
$server_file 'server.zip';

// set up basic connection
$conn_id ftp_connect($ftp_server);

// login with username and password
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id$local_file$server_fileFTP_BINARY)) {
    echo 
"Successfully written to $local_file\n";
} else {
    echo 
"There was a problem\n";
}

// close the connection
ftp_close($conn_id);

?>

更新日誌

版本 說明
4.3.0 增加了 resumepos

參見

  • ftp_pasv() - 返回目前 FTP 被動模式是否打開
  • ftp_fget() - 從 FTP 伺服器上下載一個檔案並儲存到本地一個已經打開的檔案中
  • ftp_nb_get() - 從 FTP 伺服器上獲取檔案並寫入本地檔案(non-blocking)
  • ftp_nb_fget() - 從 FTP 伺服器獲取檔案並寫入到一個打開的檔案(非阻塞)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *