Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download files using FluentFTP

Tags:

c#

ftp

fluentftp

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.

like image 225
GuidoG Avatar asked Jan 04 '17 09:01

GuidoG


Video Answer


1 Answers

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");
like image 132
Robin Rodricks Avatar answered Sep 28 '22 04:09

Robin Rodricks