1
누군가는 나가 FTP 서버에 업로드 한 파일의 시간을 어디에서 얻을 는가 저에게서 말하면 좋은가?ftp 서버에 올려 진 파일의 올려주기를 얻으십시오
class listFiles
{
public static void Main(string[] args)
{
listFiles l = new listFiles();
l.getFileList(ftpConnection,"test123","pass123"); //ftp url
}
private void getFileList(string FTPAddress, string username, string password)
{
List<string> files = new List<string>();
try
{
//Create FTP request
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
while (!reader.EndOfStream)
{
//Application.DoEvents();
// string fileType = reader.ReadLine();
files.Add(reader.ReadLine());
}
//Clean-up
reader.Close();
responseStream.Close(); //redundant
response.Close();
}
catch (Exception)
{
Console.WriteLine("There was an error connecting to the FTP Server");
}
//If the list was successfully received, display it to the user
//through a dialog
if (files.Count != 0)
{
foreach (string file in files)
{
Console.WriteLine(file);
}
}
}
고마워요 Damith하지만 lastModified 속성에 의해 나는 1/1/0001로 데이터를 얻고 있습니다. –
나는 이것이 얼마 전에 알았지 만, 비어있는 날짜를 되찾았을 때 LastModifiedDate를 가져 오는 요청에 GetDateTimeStamp 메소드가 도움이되었는지 확인했다. 'request.Method = WebRequestMethods.Ftp.GetDateTimestamp;' – Kai