如何使用 .NET 通过 SSL 上的 FTP 从 FTP 服务器下载文件?

发布于 2024-09-29 14:33:47 字数 358 浏览 8 评论 0原文

我的帖子标题几乎说明了一切:How do I download a file from an FTP server using FTP over SSL using .NET?我已经阅读了一些内容,并且有几个第三方组件可供购买来封装此功能。

问题是,这是一个非常具体的需求,并且不会增长太多,因此,如果可以使用 .NET Framework(即 System.Net 命名空间或其他东西)使用 FTP over SSL 从 FTP 服务器下载文件,那么那是最好的。我不需要大量的功能,但如果由于某种原因针对安全 FTP 服务器进行编码是一场噩梦,或者无法通过 .NET Framework BCL 实现,那么很高兴知道,因为第 3 方 .dll 可能是最好的。

谢谢你!

My post title almost states it all: How do I download a file from an FTP server using FTP over SSL using .NET? I have read a bit and there are several 3rd party components to purchase that wrap up this functionality.

The deal is, this is a very specefic need and is not going to grow much, so if downloading a file from an FTP server using FTP over SSL can be done using the .NET Framework (i.e. System.Net namespace or something), then that would be best. I don't need a ton of functionality, but if for some reason coding against a secure FTP server is a nightmare or not doable through the .NET Framework BCL that would be nice to know, as a 3rd party .dll might be best.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

破晓 2024-10-06 14:33:47

像这样:

var request = (FtpWebRequest)WebRequest.Create("ftp://...");
request.EnableSsl = true;
using (var response = request.GetResponse()) 
using (var data = response.GetResponseStream()) {
    ...
}

Like this:

var request = (FtpWebRequest)WebRequest.Create("ftp://...");
request.EnableSsl = true;
using (var response = request.GetResponse()) 
using (var data = response.GetResponseStream()) {
    ...
}
贪恋 2024-10-06 14:33:47

以下是我使用的最终 VB.NET 代码:

    Dim request As System.Net.FtpWebRequest = DirectCast(WebRequest.Create(New Uri("ftp://sftp.domain.com/myFile.txt")), System.Net.FtpWebRequest)
    request.Method = WebRequestMethods.Ftp.DownloadFile
    request.EnableSsl = True
    request.Credentials = New Net.NetworkCredential("username", "password")
    request.UsePassive = True
    Dim response As System.Net.FtpWebResponse = DirectCast(request.GetResponse(), System.Net.FtpWebResponse)

此处包含完整详细信息:

在 .NET 中使用 FTP Over SSL (SFTP) 下载 FTP 文件:
http://allen -conway-dotnet.blogspot.com/2010/11/download-ftp-files-using-ftp-over-ssl.html

Here is the final VB.NET code I used:

    Dim request As System.Net.FtpWebRequest = DirectCast(WebRequest.Create(New Uri("ftp://sftp.domain.com/myFile.txt")), System.Net.FtpWebRequest)
    request.Method = WebRequestMethods.Ftp.DownloadFile
    request.EnableSsl = True
    request.Credentials = New Net.NetworkCredential("username", "password")
    request.UsePassive = True
    Dim response As System.Net.FtpWebResponse = DirectCast(request.GetResponse(), System.Net.FtpWebResponse)

Full details here:

Download FTP Files Using FTP Over SSL (SFTP) in .NET:
http://allen-conway-dotnet.blogspot.com/2010/11/download-ftp-files-using-ftp-over-ssl.html

骷髅 2024-10-06 14:33:47

如果您需要更多功能,例如隐式 SSL、哈希验证或只是更简洁的语法,您可以使用 Ftp.dll FTP/FTPS 客户端

using(Ftp ftp = new Ftp())
{
    ftp.Connect("ftp.server.com");                       
    ftp.Login("user", "password");

    ftp.ChangeFolder("downloads");
    ftp.Download("report.txt", @"c:\report.txt");

    ftp.Close();
}

请注意,这是一个商业产品,我是作者。

If you need some more features like implicit SSL, hash verification, or just cleaner syntax you can use Ftp.dll FTP/FTPS client:

using(Ftp ftp = new Ftp())
{
    ftp.Connect("ftp.server.com");                       
    ftp.Login("user", "password");

    ftp.ChangeFolder("downloads");
    ftp.Download("report.txt", @"c:\report.txt");

    ftp.Close();
}

Please note that this is a commercial product and I'm the author.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文