我能够通过身份验证,但是我不确定如何读取CSV文件。通常从硬盘读取链接,我正在阅读这样的内容。
string[] allLines = System.IO.File.ReadAllLines(@"D:\CSV\data.csv");
但是我如何从ftp读取。我的Ftp路径就像ftp://ftp.atozfdc.com.au/data.csv
这是我通过ftp身份验证的代码。
String ftpserver = "ftp://ftp.atozfdc.com.au/data.csv";
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpserver));
reqFTP.UsePassive = false;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("username", "password");
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
最佳答案
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
//use the response like below
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string[] allLines = reader.ReadToEnd().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
关于c# - 如何使用C#从FTP读取CSV文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24236004/