(PHP 4, PHP 5)
ftp_fget — 從 FTP 服務器上下載一個文件并保存到本地一個已經打開的文件中
說明
bool ftp_fget ( resource$ftp_stream
, resource $handle
, string $remote_file
, int $mode
[, int $resumepos
= 0
] )
ftp_fget() 函數用來下載由
remote_file
指定的文件,并寫入到本地已經被打開的一個文件中。
參數
ftp_stream
FTP 連接的鏈接標識符。
handle
本地已經打開的文件的句柄。
remote_file
遠程文件的路徑。
mode
傳送模式參數,
必須是 (文本模式) FTP_ASCII
或 (二進制模式) FTP_BINARY
中的一個。
resumepos
遠程文件開始下載的位置。
返回值
成功時返回 TRUE
, 或者在失敗時返回 FALSE
。
范例
Example #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_filen";
} else {
echo "There was a problem while downloading $remote_file to $local_filen";
}
// 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 服務器獲取文件并寫入到一個打開的文件(非阻塞)