c# - How to get date and time from a file on FTP
问题描述
How to get date and time from a file on FTP? I get file for download, but I need get date and hour of each file.
I am build a console application in c# and I need verify the file date for download decision .
Follow my code now.
static void DownloadAllFilesFTP(string urlFTP, string user, string password)
{
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(urlFTP);
ftpRequest.Credentials = new NetworkCredential(user, password);
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
List<string> directory = new List<string>();
string line = streamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
directory.Add(line);
line = streamReader.ReadLine();
}
streamReader.Close();
using (WebClient ftpClient = new WebClient())
{
ftpClient.Credentials = new System.Net.NetworkCredential(user, password);
for (int i = 0; i <= directory.Count - 1; i++)
{
if (directory[i].Contains("."))
{
if (directory[i].Contains(""))
{
string pathRemota = urlFTP + directory[i].ToString();
string pathLocal = Path.Combine(Directory.GetCurrentDirectory(), directory[i].ToString());
ftpClient.DownloadFile(pathRemota, pathLocal);
}
}
}
}
}
解决方案
推荐阅读
- javascript - javascript for 循环只执行一次
- rest - Spring Web:将 URL 映射到独立的 Spring 应用程序
- html - CSS - 如何在表格的列之间添加行
- ios - Swift UITest - 将使用两者之一。哪个是未定义的
- javascript - 添加图层时,Mapbox 样式在缩放时更改/中断
- apache-spark - Spark 作业可在两种不同的 HDFS 环境中工作
- elasticsearch - Elasticsearch 无痛查询异常
- spring-boot - 突然得到“LoggerFactory 不是 Logback LoggerContext 但 Logback 在类路径上。” 并且无法运行
- mongodb - 从 mongodb 的嵌套数组中仅检索匹配的对象
- c# - C# Selenium Firefox - 错误异常“浏览上下文已被丢弃”