PHP 中的 ftp_fget() 函数
ftp_fget() 函数用于从 FTP 服务器下载文件并将其保存在打开的本地文件中
语法
ftp_fget(con,open_file,server_file,mode,startpos);
参数
con − FTP 连接
open_file − 存储数据的文件
server_file − 要下载的服务器文件
mode − 传输模式
startpos − 开始下载的位置。于 PHP 4.3.0 中添加。
返回值
成功时 ftp_fget() 函数返回 TRUE,失败时返回 FALSE。
示例
以下是一个示例,我们将下载服务器文件 “demo.txt” 并将其保存在打开的本地文件 “new.txt” 中 −
<?php
$ftp_server="192.168.0.4";
$ftp_user="amit";
$ftp_pass="tywg61gh";
$con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($con, $ftp_user, $ftp_pass);
$my_serverfile = "demo.txt";
$local_file = "new.txt";
$file_pointer = fopen($local_file,"w");
if (ftp_fget($con, $file_pointer, $my_serverfile, FTP_ASCII, 0)) {
echo "Written to $local_file!";
} else {
echo "Error in downloading the $my_serverfile!";
}
ftp_close($con);
fclose($file_pointer);
?>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP