FTP从服务器直接下载文件到客户端 [英] FTP download file from server directly into client

查看:35
本文介绍了FTP从服务器直接下载文件到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将文件从 FTP 服务器下载到客户端.如果我使用ftp_get,文件被下载到PHP服务器,它可以将输出写入浏览器.所以下载过程是

I try to download a file from FTP server into client. If I use ftp_get, the file is downloaded into PHP server, which can write the output into browser. So the download process is

FTP server -> PHP server -> client

这会使流量翻倍 - 这对下载大文件很不利.有一种方法可以将文件直接写入此处描述的浏览器:流式 FTP 下载到输出 - 但无论如何数据都会流经 PHP 服务器,对吗?

This doubles traffic - this is bad in downloading big files. There is a way how to write the file directly into the browser described here: Stream FTP download to output - but the data flows through PHP server anyway, am I right?

有什么方法可以建立这个下载(如果是,怎么做?),还是根本不可能?

Is there any way how to establish this download (if yes, how?), or is it principially impossible?

FTP server -> client

它还应该以安全的方式与非匿名 FTP 服务器一起使用.

it should work also with non-anonymous FTP servers in secure way.

推荐答案

试试下面的代码.

$curl = curl_init();
$file = fopen("ls-lR.gz", 'w');
curl_setopt($curl, CURLOPT_URL, "ftp://ftp.sunet.se/ls-lR.gz"); #input
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_exec($curl);

谢谢.

这篇关于FTP从服务器直接下载文件到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆