dtng5978 2010-10-22 11:11
浏览 48
已采纳

提供下载到受密码保护的FTP的链接

I have a FTP with some file which I want give it to the users for Downloading. But the FTP is password protected and I want to authenticate the FTP using PHP and make the links available in a php page so as that when the User clicks on any of the FTP links in that page, the download should start.

Please help.

  • 写回答

1条回答 默认 最新

  • drhdjp97757 2010-10-22 11:19
    关注

    You could use PHP's fopen wrappers to open the FTP location by PHP from your server, and pass it on to the user as a normal HTTP response:

    // you can use application/octet-stream to force download
    header ('Content-Type: ' . $content_type_of_your_file); 
    
    // open file and pass it to output
    readfile ('ftp://username:password@example.com/path/to/your.file');
    

    As @Alan mentioned, if the FTP server is somewhere outside your network, this will generate additional traffic. You could wrap this in a caching scheme - e.g. only download if you don't have a copy on your web server, and if you do, check for freshness. Then you're essentially building a HTTP mirror of the FTP site, and it may be prudent to pre-fetch the files to your cache before they're requested by the users.

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

报告相同问题?

悬赏问题

  • ¥15 关于LT3758反激式负压电源,功率三极管烧毁的问题
  • ¥20 aruba ap305 CAP转IAP
  • ¥20 rockchip rk3588 ffmedia运行异常
  • ¥30 如何用 Java 简单系统设计?(相关搜索:服务器|面向对象设计|随机数)
  • ¥15 鸿蒙开发(关键词-开发环境)
  • ¥15 错误使用 mex Embedding metadata in the MEX file failed.
  • ¥30 Fractal eXtreme 64-bit求解锁15天限制
  • ¥30 openvpn 启动错误
  • ¥15 有偿解决脑电仪导出数据edf时出现报错,有偿
  • ¥15 关于下载R包”org.Hs.eg.db“的时候,遇到了could not find function "file.edit"的问题!