1

我的帖子标题几乎说明了一切:如何使用 .NET 使用 FTP over SSL 从 FTP 服务器下载文件?我已经阅读了一些内容,并且可以购买几个包含此功能的第 3 方组件。

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

谢谢!

4

3 回答 3

5

像这样:

var request = (FtpWebRequest)WebRequest.Create("ftp://...");
request.EnableSsl = true;
using (var response = request.GetResponse()) 
using (var data = response.GetResponseStream()) {
    ...
}
于 2010-10-28T19:22:13.823 回答
4

这是我使用的最终 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

于 2010-11-01T18:11:35.937 回答
0

如果您需要更多功能,例如隐式 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();
}

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

于 2010-11-27T01:12:07.383 回答