使用FluentFTP下载文件

时间:2017-01-04 09:15:36

标签: c# ftp fluentftp

我正在尝试使用C#中的FluentFTP实现FTP传输。获取目录列表非常简单,但我无法下载文件。

我发现有一篇文章在其评论中有一个例子,但它不会编译,因为我找不到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()方法来获取流,而不是将该流保存到文件中。

1 个答案:

答案 0 :(得分:14)

现在,最新版本的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");
相关问题