[英]FTP download file from server directly into client
我尝试将文件从 FTP 服务器下载到客户端。 如果我使用ftp_get
,文件被下载到 PHP 服务器,可以将 output 写入浏览器。 所以下载过程是
FTP server -> PHP server -> client
这会使流量翻倍——这对下载大文件很不利。 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?
有什么方法可以建立这个下载(如果是,怎么做?),还是根本不可能?
FTP server -> client
编辑:它也应该以安全的方式与非匿名 FTP 服务器一起使用。
<a href="ftp://server/file.ext">Download the file</a>
;-)
如果客户端可以直接访问相关文件(即不需要秘密用户名或密码),只需将他重定向到该文件:
header('Location: ftp://example.com/foobar');
这将导致客户端直接访问 URL。 但是,您无法控制客户端会做什么。 浏览器可能只是开始下载文件,但它也可能启动 FTP 客户端或执行您可能关心或不关心的其他事情。
尝试下面的代码。
$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);
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.