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

查看:233
本文介绍了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天全站免登陆