douhe8981 2015-06-04 04:24
浏览 31
已采纳

如何在不使用主机带宽传输的情况下从其他FTP主机读取文件

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?

  • 写回答

1条回答 默认 最新

  • dqq46733 2015-06-04 05:27
    关注

    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".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加