我正在尝试获取特定目录中的文件列表,然后我想检查它们的最后修改日期。
初始请求工作正常:
FtpWebRequest request;
request = (FtpWebRequest)WebRequest.Create(new Uri(FtpPath));
request.Credentials = new NetworkCredential("username", "password");
request.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string FileNames = reader.ReadToEnd();
然后经过一些处理,我选择我感兴趣的文件并尝试检索它们的时间戳。以下情况在循环中发生:
request = (FtpWebRequest)WebRequest.Create(new Uri(FtpPath + Files[i]));
request.Credentials = new NetworkCredential("username", "password");
request.Method = WebRequestMethods.Ftp.GetDateTimestamp;
response = (FtpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
reader = new StreamReader(responseStream);
FileDates = reader.ReadToEnd();
我的FileDates
变量永远不会被设置为任何东西。我很想把它打包在一个类中以避免可怕的代码重复,但现在我会满足于能够检索我感兴趣的数据。