【问题标题】:Download files using FluentFTP使用 FluentFTP 下载文件
【发布时间】:2017-05-18 12:32:40
【问题描述】:

我正在尝试在 C# 中使用 FluentFTP 实现 FTP 传输。获取目录列表很容易,但我一直在下载文件。

我在这里找到一篇文章,它的 cmets 中有一个示例,但它无法编译,因为我找不到 FtpFile 类的来源。

有没有人举例说明如何使用 FluentFTP 从 ftp 服务器下载文件?

编辑:我在这里找到了一些示例 https://github.com/hgupta9/FluentFTP 但是没有关于如何实际下载文件的示例。

在这篇文章 Free FTP Library 中有一个例子,但它不能编译。这是例子

FtpClient ftp = new FtpClient(txtUsername.Text, txtPassword.Text, txtFTPAddress.Text);
FtpListItem[] items = ftp.GetListing(); 
FtpFile file = new FtpFile(ftp, "8051812.xml"); // THIS does not compile, class FtpFile is unknown
file.Download("c:\\8051812.xml");
file.Name = "8051814.xml";
file.Download("c:\\8051814.xml");
ftp.Disconnect();

编辑:解决方案
我发现的文章包含一个让我走错方向的例子。 似乎曾经有一个下载方法,但现在很久以前就没有了。 所以答案是放手,使用 OpenRead() 方法获取流,然后将该流保存到文件中。

【问题讨论】:

    标签: c# ftp fluentftp


    【解决方案1】:

    现在最新版本的 FluentFTP 中内置了 DownloadFile()UploadFile() 方法。

    来自https://github.com/robinrodricks/FluentFTP#example-usage的示例用法:

    // connect to the FTP server
    FtpClient client = new FtpClient();
    client.Host = "123.123.123.123";
    client.Credentials = new NetworkCredential("david", "pass123");
    client.Connect();
    
    // upload a file
    client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt");
    
    // rename the uploaded file
    client.Rename("/htdocs/big.txt", "/htdocs/big2.txt");
    
    // download the file again
    client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/big2.txt");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 2016-01-06
      相关资源
      最近更新 更多