2013-04-15 1 views
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); 
      } 
     } 
    } 

답변

0

파일을 FTP로 전체 경로를 구축 해당 파일 이름을 사용하여 당신은 이미 파일의 목록을 가지고 당신이 당신의 현재 코드에서 각 파일에 대해 응답을받을 필요가 FtpWebResponse.LastModified Property

using (FtpWebResponse resp = (FtpWebResponse)request.GetResponse()) 
{ 
    var lastModified = resp.LastModified ; 
} 

으로 시도 생성 날짜를 찾아야합니다. 그 후 전체 ftp 파일 경로에 대한 ftp 요청을 만듭니다. 그러면 응답 객체의 마지막 수정 날짜를 읽을 수 있습니다.

+0

고마워요 Damith하지만 lastModified 속성에 의해 나는 1/1/0001로 데이터를 얻고 있습니다. –

+0

나는 이것이 얼마 전에 알았지 만, 비어있는 날짜를 되찾았을 때 LastModifiedDate를 가져 오는 요청에 GetDateTimeStamp 메소드가 도움이되었는지 확인했다. 'request.Method = WebRequestMethods.Ftp.GetDateTimestamp;' – Kai

관련 문제