11

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.

0

1 Answer 1

23

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");
0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.