代码之家  ›  专栏  ›  技术社区  ›  atconway

如何使用ftp通过ssl使用.net从ftp服务器下载文件?

  •  1
  • atconway  · 技术社区  · 15 年前

    我的文章标题几乎说明了这一切:如何使用ftp从ftp服务器通过ssl使用.net下载文件?我已经读了一点,有几个第三方组件要购买,总结了这个功能。

    交易是,这是一个非常具体的需求,不会增长太多,所以如果可以使用.NET框架(即System.NET命名空间或其他东西)从使用FTP over SSL的FTP服务器下载文件,那么这是最好的。我不需要太多的功能,但是如果出于某种原因,针对安全的FTP服务器进行编码是一场噩梦,或者无法通过.NET框架BCL实现,那么最好知道这一点,因为作为第三方.dll可能是最好的。

    谢谢您!

    3 回复  |  直到 15 年前
        1
  •  5
  •   SLaks    15 年前

    这样地:

    var request = (FtpWebRequest)WebRequest.Create("ftp://...");
    request.EnableSsl = true;
    using (var response = request.GetResponse()) 
    using (var data = response.GetResponseStream()) {
        ...
    }
    
        2
  •  4
  •   atconway    15 年前

    下面是我使用的最后一个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)
    

    详细信息如下:

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

        3
  •  0
  •   Pawel Lesnikowski    15 年前

    如果你需要更多的功能,比如 隐式SSL ,散列验证,或者只使用更清晰的语法 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();
    }
    

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

    推荐文章