我正在尝试使用FluentFTP在C#中实现FTP传输。获取目录列表非常容易,但我只能下载文件。
我在这里找到了一篇文章,它的注释中有一个例子,但是它不会编译,因为我找不到类FtpFile的来源。
有人有使用FluentFTP从ftp服务器下载文件的示例吗?
编辑:--我在这里找到了一些示例,https://github.com/hgupta9/FluentFTP,但是没有关于如何实际下载文件的示例。
在本文中,有一个示例,但它没有编译。这是一个例子
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()方法获得一个流,而不是将该流保存到文件中。
发布于 2017-01-28 16:40:59
现在,DownloadFile()和UploadFile()方法都内置到了FluentFTP的最新版本中。
来自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");https://stackoverflow.com/questions/41460069
复制相似问题