ftp_fget
(PHP 4, PHP 5, PHP 7, PHP 8)
ftp_fget — 從 FTP 伺服器上下載一個檔案並儲存到本地一個已經打開的檔案中
說明
ftp_fget(
resource
resource
string
int
int
): bool
resource
$ftp_stream
,resource
$handle
,string
$remote_file
,int
$mode
,int
$resumepos
= 0): bool
ftp_fget() 函式用來下載由
remote_file
指定的檔案,並寫入到本地已經被打開的一個檔案中。
參數
-
ftp_stream
-
FTP 連線的鏈接識別符號。
-
handle
-
本地已經打開的檔案的控制代碼。
-
remote_file
-
遠端檔案的路徑。
-
mode
-
傳送模式參數, 必須是 (文字模式)
FTP_ASCII
或 (二進制模式)FTP_BINARY
中的一個。 -
resumepos
-
遠端檔案開始下載的位置。
返回值
成功時返回 true
, 或者在失敗時返回 false
。
範例
示例 #1 ftp_fget() 例子
<?php
// path to remote file
$remote_file = 'somefile.txt';
$local_file = 'localfile.txt';
// open some file to write to
$handle = fopen($local_file, 'w');
// 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 $remote_file and save it to $handle
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
echo "successfully written to $local_file\n";
} else {
echo "There was a problem while downloading $remote_file to $local_file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($handle);
?>
更新日誌
版本 | 說明 |
---|---|
4.3.0 |
增加了resumepos 的支援。
|
參見
- ftp_get() - 從 FTP 伺服器上下載一個檔案
- ftp_nb_get() - 從 FTP 伺服器上獲取檔案並寫入本地檔案(non-blocking)
- ftp_nb_fget() - 從 FTP 伺服器獲取檔案並寫入到一個打開的檔案(非阻塞)