gpt4 book ai didi

c# - 使用 FluentFTP 下载文件

转载 作者:太空狗 更新时间:2023-10-29 20:56:12 26 4
gpt4 key购买 nike

我正在尝试在 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() 方法获取流并将该流保存到文件中。

最佳答案

最新版本的 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");

关于c# - 使用 FluentFTP 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41460069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com