我将文件夹名称XYZ放入ftp服务器[ftp://ftp00.abcd.net]。我有一些xml文件进入XYZ文件夹,如Lggggg.XML。我想下载多个文件,如Lgggg.XML。现在我只能下载文件,这就是我想知道文件数量的原因[Lgggg.XML]然后我会在for循环中运行下载文件代码。我想计算存在于ftp://ftp00.abcd.net/XYZ中的那些xml文件。我通过网络搜索,但我找不到合适的解决方案。任何有关此信息都将有所帮助。请帮忙。
修改 我的C#代码
FtpWebRequest ftpwebrequest = (FtpWebRequest)WebRequest.Create("ftp://ftp00.abcd.net/XYZ");
ftpwebrequest.Credentials = new NetworkCredential("username", "pwd");
ftpwebrequest.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftpwebrequest.GetResponse();
Console.WriteLine("user looged in");
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);
var list = Directory.GetFiles("vit-gent-maid", "*.XML");
int count = list.Length;
Console.WriteLine("count :" + count);
using (WebClient ftpClient = new WebClient())
{
ftpClient.Credentials = new System.Net.NetworkCredential("username", "pwd");
ftpClient.DownloadFile("ftp://ftp00.abcd.net/XYZ/Lggggg.XML", @"C:\\Temp\XML\Lggggg.XML");
Console.WriteLine("file transfer successful");
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}