使用FluentFTP下载文件 [英] Download files using FluentFTP

查看:180
本文介绍了使用FluentFTP下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to implement FTP transfer using FluentFTP in C#. Getting a directory listing is very easy, but I am stuck on downloading files.

我发现有一篇文章的注释中有一个示例,但是由于无法找到FtpFile类的来源而无法编译.

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.

有人知道如何使用FluentFTP从ftp服务器下载文件吗?

Does anybody have an example of how tocan I download a file from an ftp server using FluentFTP ?

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

I found some examples here https://github.com/hgupta9/FluentFTP But there is no example on how to actually download a file.

本文免费FTP库中有一个示例,但未编译.这是例子

In the this article Free FTP Library there is an example but it does not compile. 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();

编辑:解决方案
我发现的文章包含一个示例,使我误入歧途. 似乎曾经有一个Download方法,但现在已经不复存在了. 因此,答案是放任不管,并使用OpenRead()方法获取流,而不是将该流保存到文件中.

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.

推荐答案

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

There are now DownloadFile() and UploadFile() methods built into the latest version of FluentFTP.

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

// 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");

这篇关于使用FluentFTP下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆