CSVhelper to read csv file from ftp server

Polachan Paily 91 Reputation points
2022-05-14T23:14:13.877+00:00

Please can you any one help me how to read csv file from ftp server using CSVhelper. I have to read the file from "ftp://myfiles.com/download". If search the google I can see CSV helper is being used to read only local csv file not from ftp. Please any help would be very appreciated

Thanks
Pol

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,248 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sreeju Nair 11,606 Reputation points
    2022-05-15T06:38:53.023+00:00

    Since your file is in FTP, first you need to download file. You may use WebClient or FTPWebRequest class to download the file. You can load your file to a MemoryStream and let the CSVHelper reads the file from the memorystream. Refer this https://joshclose.github.io/CsvHelper/examples/prerequisites/streams/

    A sample is here:
    https://github.com/JoshClose/CsvHelper/issues/1412#issuecomment-551122734

    Note: for the above sample, it uses MemoryStream, in your case, you can download the file from FTP to byte[] and then construct a MemoryStream from the byte[], then use CSVHelper

    1 person found this answer helpful.
    0 comments No comments