PHP 中的 ftp_get() 函数
phpprogrammingserver side programming更新于 2025/5/26 11:07:17
ftp_get() 函数用于从 FTP 服务器下载文件并将其保存到本地文件中。
语法
ftp_fget(con,local_file,server_file,mode,startpos);
参数
con − FTP 连接
local_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";
$my_file = "new.txt";
if (ftp_fget($con, $my_file, $my_serverfile, FTP_ASCII, 0)) {
echo "Written to local file!";
} else {
echo "Error in downloading the server file!";
}
ftp_close($con);
fclose($file_pointer);
?>

