我想要的FTP文件夹的内容下载到使用在计算器上一本例中的本地文件夹:
Downloading a list of files from ftp to local folder using c#?检索列表,无需额外的细节
我的代码此刻是:
public void DownloadFilesFromFTP(string localFilesPath, string remoteFTPPath)
{
remoteFTPPath = "ftp://" + Hostname + remoteFTPPath;
var request = (FtpWebRequest)WebRequest.Create(remoteFTPPath);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential(Username, Password);
request.Proxy = null;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
List<string> directories = new List<string>();
string line = reader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
directories.Add(line);
line = reader.ReadLine();
}
reader.Close();
using (WebClient ftpClient = new WebClient())
{
ftpClient.Credentials = new System.Net.NetworkCredential(Username, Password);
for (int i = 0; i <= directories.Count - 1; i++)
{
if (directories[i].Contains("."))
{
string path = remoteFTPPath + @"/" + directories[i].ToString();
string trnsfrpth = localFilesPath + @"\" + directories[i].ToString();
ftpClient.DownloadFile(path, trnsfrpth);
}
}
}
response.Close();
}
我收到的路径不支持例外,当我检查我的变量path
和trnsfrpth
的价值观,他们似乎是包括Apache的信息。
路径:ftp://hostname/data/resourceOrders/-rw-r--r-- 1阿帕奇
阿帕奇367 7月16日14:07资源订单1437019656813-893.json
而且
trnsfrpth:五: \ code.runner \ local \ orders-rw-r - r-- 1 apache apache
367 Jul 16 14:07 resource-orders-1437019 656813-893.json
我如何能捕捉不仅是文件名,resource-orders-1437019656813-893.json
没有哈克(rightof()
,例如)的方法呢?
简直不敢相信。非常感谢你! – Codingo