ftp_get() 函数在 PHP 中
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);
?>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP