首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ftp_fget

(PHP 4, PHP 5, PHP 7)

ftp_fget - 从FTP服务器下载文件并保存到打开的文件

描述

代码语言:javascript
复制
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()示例

代码语言:javascript
复制
<?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);
?>

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com