ASP.NET FTP Download

2019-08-17 01:06发布

问题:

I have a need to push out a file package that includes a driver via my website for download. The only issue is it cannot be transferred in ASCII mode or else it becomes corrupt. I've looked at alternatives for FTP download but would rather not have an application that is created that can be downloaded just to transfer files. I'm looking into the possibility of creating an ASP.NET page that will use FTP for the download process.

I've seen a few examples but I also have a few questions:

  1. How best to protect the login/password information instead of putting it in code? Can that be referenced from web.config?
  2. Any possibility of showing download progress? Is AJAX my only option?
  3. Ability to allow the user to select a download location on their local machine?

EDIT Could I add a MIME type for ZIP and EXE files of application/octet-stream that would force a Binary download of the files?

回答1:

You can use the WebClient class.

using (WebClient ftpClient = new WebClient())
{
    ftpClient.DownloadFile("ftp://domain.org/file.txt", "file.txt");
}

For authenticated requests

using (WebClient ftpClient = new WebClient())
{
    ftpClient.DownloadFile("ftp://user:pass@domain.org/file.txt", "file.txt");
}


回答2:

Why FTP? You could create an HTTP Handler to push down the binaries. Here is more information on HTTP Handlers: http://www.15seconds.com/issue/020417.htm



标签: asp.net ftp