我正在尝试使用C#中的FluentFTP实现FTP传输.获取目录列表非常简单,但我坚持下载文件.
我发现有一篇文章在其评论中有一个例子,但它不会编译,因为我无法找到FtpFile类的来源.
有没有人举例说明我是如何使用FluentFTP从ftp服务器下载文件的?
编辑:我在这里找到了一些例子https://github.com/hgupta9/FluentFTP但是没有关于如何实际下载文件的例子.
在本文中免费FTP库有一个例子,但它不编译.这是一个例子
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();
Run Code Online (Sandbox Code Playgroud)
编辑:解决方案
我发现的文章包含一个让我走错方向的例子.似乎曾经有过一种下载方法,但现在已经很久了.所以答案就是让它去使用OpenRead()方法来获取流,而不是将该流保存到文件中.
Rob*_*cks 16
现在有最新版本的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");
Run Code Online (Sandbox Code Playgroud)