0

I am trying to read a CSV file from my FTP server.

I created the connection:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://myserver.com/report_2018_10_23.csv");
            request.Method = WebRequestMethods.Ftp.DownloadFile;

            request.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
            request.UsePassive = true;
            request.UseBinary = true;
            request.EnableSsl = false;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

How can I read the response content? Can I use File.ReadAllText with the response content?

Thanks

Max Boy
  • 317
  • 6
  • 21
  • Particularly see [my answer](https://stackoverflow.com/q/6098694/850848#47259033), which covers several different ways to read a text file from FTP server - pick the one that suits your need sthe best. – Martin Prikryl Oct 24 '18 at 18:49
  • You answer is really good, but it is about how to download the file. My problem is how to read the .csv file from FTP server – Max Boy Oct 24 '18 at 19:39
  • The question (and my answer) is about **reading**. Please read it again. – Martin Prikryl Oct 24 '18 at 19:42
  • Maybe you are missing that “downloading” is actually the same thing as “reading (from a server)”. Only by “downloading” people usually mean “downloading to a file”. While by “reading” people usually mean “downloading to a memory” (what the linked question is about). The transfer part of both operations is identical. The difference is only in a way how the downloaded data are stored locally. – Martin Prikryl Oct 24 '18 at 19:53
  • Ok. Thank you. How can I open a .csv file after downloading it from FTP? – Max Boy Oct 24 '18 at 19:59
  • *"open"* is a very broad term. What do you want to do with the contents? – Martin Prikryl Oct 24 '18 at 19:59
  • I just one to grab the values in the column name "CustomID" – Max Boy Oct 24 '18 at 20:01
  • Do the same, what would you do, had you read a local file contents using the `File.ReadAllText`. Except that you will use `WebClient.DownloadString` instead of `File.ReadAllText`. – Martin Prikryl Oct 24 '18 at 20:03
  • 1
    Got it! Thank you – Max Boy Oct 24 '18 at 20:11

0 Answers0