ASP.NET FTP下载 [英] ASP.NET FTP Download

查看:76
本文介绍了ASP.NET FTP下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过我的网站推出一个包含驱动程序的文件包以供下载.唯一的问题是它无法以ASCII模式传输,否则会损坏.我已经看过FTP下载的替代方法,但宁愿没有一个可以下载的应用程序,也可以仅下载该文件来传输文件.我正在研究创建一个使用FTP进行下载过程的ASP.NET页面的可能性.

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. 如何最好地保护登录名/密码信息而不是将其放入代码中?可以从web.config引用吗?
  2. 是否有可能显示下载进度?AJAX是我唯一的选择吗?
  3. 是否可以允许用户在其本地计算机上选择下载位置?

编辑是否可以为 application/octet-stream 的ZIP和EXE文件添加MIME类型,以强制二进制下载文件?

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?

推荐答案

您可以使用WebClient类.

You can use the WebClient class.

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

对于已验证的请求

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

这篇关于ASP.NET FTP下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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