首页 > 解决方案 > 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);
                    }
                }
            }
        }
}

标签: c#dateftpwebrequesthour

解决方案


推荐阅读