简体   繁体   English

使用 FluentFTP 下载文件

[英]Download files using FluentFTP

I am trying to implement FTP transfer using FluentFTP in C#.我正在尝试在 C# 中使用 FluentFTP 实现 FTP 传输。 Getting a directory listing is very easy, but I am stuck on downloading files.获取目录列表非常容易,但我一直在下载文件。

I found one article that has an example in its comments here but it won't compile because I cannot find where the class FtpFile comes from.我发现一篇文章在这里的评论中有一个示例,但它无法编译,因为我找不到 FtpFile 类的来源。

Does anybody have an example of how tocan I download a file from an ftp server using FluentFTP ?有人有如何使用 FluentFTP 从 ftp 服务器下载文件的示例吗?

EDIT: I found some examples here https://github.com/hgupta9/FluentFTP But there is no example on how to actually download a file.编辑:我在这里找到了一些例子https://github.com/hgupta9/FluentFTP但是没有关于如何实际下载文件的例子。

In the this article Free FTP Library there is an example but it does not compile.在这篇文章 Free FTP Library 中有一个例子,但它不能编译。 This is the example这是例子

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();

EDIT: The solution编辑:解决方案
The article I found contained an example that set me in the wrong direction.我发现的这篇文章包含了一个让我走向错误方向的例子。 It seems there was once a Download method but that is gone long ago now.似乎曾经有一种下载方法,但现在很久以前就没有了。 So the answer was to let that go and use the OpenRead() method to get a stream and than save that stream to a file.所以答案是放手并使用 OpenRead() 方法来获取一个流,然后将该流保存到一个文件中。

There are now DownloadFile() and UploadFile() methods built into the latest version of FluentFTP.现在,最新版本的 FluentFTP 中内置了DownloadFile()UploadFile()方法。

Example usage from https://github.com/robinrodricks/FluentFTP#example-usage :来自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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM