Download files using FluentFTP

本小妞迷上赌 提交于 2019-12-21 12:15:28

问题


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.

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.

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

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

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

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.


回答1:


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

Example usage from 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/download-files-using-fluentftp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!