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.

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

报告相同问题?