ftp_fget
(PHP 4, PHP 5, PHP 7)
ftp_fget - 从FTP服务器下载文件并保存到打开的文件
描述
bool ftp_fget ( resource $ftp_stream , resource $handle , string $remote_file , int $mode [, int $resumepos = 0 ] )
ftp_fget()remote_file
从FTP服务器检索,并将其写入给定的文件指针。
参数
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);
?>
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com