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

ftp_get

(PHP 4, PHP 5, PHP 7)

ftp_get - 从FTP服务器下载文件

描述

代码语言:javascript
复制
bool ftp_get ( resource $ftp_stream , string $local_file , string $remote_file , int $mode [, int $resumepos = 0 ] )

ftp_get()从FTP服务器检索远程文件,并将其保存到本地文件中。

参数

ftp_stream

FTP连接的链接标识符。

local_file

本地文件路径(如果文件已经存在,将被覆盖)。

remote_file

远程文件路径。

mode

传输模式。必须是FTP_ASCII或者FTP_BINARY

resumepos

在开始从远程文件中下载的位置。

返回值

成功时返回TRUE或失败时返回FALSE

例子

示例#1 ftp_get()示例

代码语言:javascript
复制
<?php

// define some variables
$local_file = 'local.zip';
$server_file = 'server.zip';

// 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 $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

?>

扫码关注腾讯云开发者

领取腾讯云代金券