【发布时间】:2014-06-16 02:38:51
【问题描述】:
我能够通过身份验证,但我不确定如何读取 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();
【问题讨论】:
-
您是否需要代理凭据才能连接到您的 ftp?尝试此代码时是否有任何异常?
-
我没有收到任何错误我在问如何从我的本地计算机获取文件路径,例如我通过我的文件路径这样 System.IO.File.ReadAllLines(@"D:\CSV \data.csv");