如何在不使用主机带宽传输的情况下从另一个FTP主机读取文件 [英] How to read file from another FTP host without use host bandwidth transfer

查看:98
本文介绍了如何在不使用主机带宽传输的情况下从另一个FTP主机读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储数据主机和一个下载主机(该主机没有数据库)。我想从商店主机中的下载主机中读取文件并将其提供给用户下载,但我不想使用每月带宽传输存储主机当用户正在下载文件时,只需使用下载主机带宽传输。 有两种方法我知道:


  1. ftp_get 下载并保存文件一个本地文件,然后设置进行下载。

      //在商店主机中
    $ local_file
    我不想使用这种方式,因为下载文件存储在主机中。 ='app.apk';
    $ ftp_file ='/uploads/2015/06/1eb6a628c60bb69a6b6092d03e252c29.apk';
    //下载文件并保存到本地
    ftp_get($ conn_id,$ local_file,$ ftp_file,FTP_BINARY);

    $ file_name ='app.apk';
    $ file_size = filesize($ local_file);

    header('Content-Description:File Transfer');
    header('Content-Type:application / octet-stream');
    header('Content-Disposition:attachment; filename ='。$ file_name);
    header('Content-Transfer-Encoding:binary');
    header('Connection:Keep-Alive');
    header('Expires:0');
    header('Cache-Control:must-revalidate,post-check = 0,pre-check = 0');
    header('Pragma:public');
    header('Content-Length:'。$ file_size);

    readfile($ local_file);


  2. 我不知道 file_get_contents 当用户正在下载文件时,使用存储主机的带宽传输。

      //在商店主机
    header('Content-Description:File Transfer');
    header('Content-Type:application / octet-stream');
    header('Content-Disposition:attachment; filename ='。$ file_name);
    header('Content-Transfer-Encoding:binary');
    header('Connection:Keep-Alive');
    header('Expires:0');
    header('Cache-Control:must-revalidate,post-check = 0,pre-check = 0');
    header('Pragma:public');
    header('Content-Length:'。$ file_size);

    // readfile($ local_file);

    $ c = file_get_contents('ftp:// login:pass@download-host.com/uploads/2015/06/app.apk');
    echo $ c;


我不想使用带宽转移在商店主机中;我可以使用哪种方式?方式2或其他方式?

解决方案

没有办法将内容从下载主机直接下载到客户端,为客户提供下载所需的所有信息(下载链接)。



如果您需要隐藏客户端的下载信息,则需要下载文件放在商店主机上,然后转发给客户端。因此,您正在使用商店主机的带宽数据。使用什么技术,协议或功能并不重要。而且, ftp_get file_get_contents(ftp:// ...)同样使用相同的代码。简单地说,既不能隐藏客户端的下载信息,也不能使用商店主机的带宽数据。

/ p>

I have a host for store data and a download host (this host doesn't have database). I want to read a file from download host in store host and give it to user for download but I don't want to use monthly bandwidth transfer of store host when user is downloading file and just use download host bandwidth transfer.

There are two ways that I know:

  1. ftp_get download the file and save it in a local file and then set header for download. I don't want use this way because download file in store host.

    // in store host
    $local_file = 'app.apk';
    $ftp_file = '/uploads/2015/06/1eb6a628c60bb69a6b6092d03e252c29.apk';
    // download file and save it in local
    ftp_get($conn_id , $local_file, $ftp_file, FTP_BINARY);
    
    $file_name = 'app.apk';
    $file_size = filesize($local_file);
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $file_name);
    header('Content-Transfer-Encoding: binary');
    header('Connection: Keep-Alive');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . $file_size);
    
    readfile($local_file);
    

  2. I don't know file_get_contents use bandwidth transfer of store host when user is downloading file or not.

    // in store host
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $file_name);
    header('Content-Transfer-Encoding: binary');
    header('Connection: Keep-Alive');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . $file_size);
    
    // readfile($local_file);
    
    $c = file_get_contents('ftp://login:pass@download-host.com/uploads/2015/06/app.apk');
    echo $c;
    

I don't want to use bandwidth transfer in store host; Which way can I use? Way 2 or another way?

解决方案

There's no way to download a contents from the "download host" directly to the client, without providing the client with all the information needed for the download ("download link").

If you need to hide the download information from the client, you need to download the file on the "store host" and then forward it to the client. Hence you are consuming bandwidth data of the "store host". It does not matter what technology, protocol or function you use. And the ftp_get and file_get_contents("ftp://...") use both the same code behind anyway.

Simply said, there's no way to both hide the download information from the client and not use bandwidth data of the "store host".

这篇关于如何在不使用主机带宽传输的情况下从另一个FTP主机读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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