C#中 使用 WebRequestMethods.Ftp.GetDateTimestamp 获取ftp文件最后修改时间
具体代码如下,如第一次获取文件aa.txt的修改时间时可以得到(2012-02-04 16:35:25),第二次获取的时候(实际上aa.txt文件已经被修改,及修改时间变了,如2012-02-04 16:35:40),但是读取出来的时间仍然为(2012-02-04 16:35:25),不知是何原因??求解
public static DateTime GetFileModifyDateTime(string ftpServerIP,string ftpFolder,string ftpUserID,string ftpPwd, string fileName)
{
FtpWebRequest reqFTP=null;
try
{
if (ftpFolder != "")
{
ftpFolder = ftpFolder.Replace("/", "").Replace("\\", "");
ftpFolder = "/" + ftpFolder;
}
string ftpPath = "ftp://" + ftpServerIP + ftpFolder + "/" + fileName;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath));
reqFTP.UseBinary = true;
//reqFTP.UsePassive = false;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPwd);
reqFTP.Method = WebRequestMethods.Ftp.GetDateTimestamp;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
DateTime dt = response.LastModified;
response.Close();
response = null;
reqFTP = null;
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
public static DateTime GetFileModifyDateTime(string ftpServerIP,string ftpFolder,string ftpUserID,string ftpPwd, string fileName)
{
FtpWebRequest reqFTP=null;
try
{
if (ftpFolder != "")
{
ftpFolder = ftpFolder.Replace("/", "").Replace("\\", "");
ftpFolder = "/" + ftpFolder;
}
string ftpPath = "ftp://" + ftpServerIP + ftpFolder + "/" + fileName;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath));
reqFTP.UseBinary = true;
//reqFTP.UsePassive = false;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPwd);
reqFTP.Method = WebRequestMethods.Ftp.GetDateTimestamp;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
DateTime dt = response.LastModified;
response.Close();
response = null;
reqFTP = null;
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
...全文
相关推荐
通过FTP读取文件属性而不下载文件。
嗨,我如何不用下载就可以通过FTP读取文件属性?谢谢您的宝贵时间。
《模式识别与数据挖掘》配套PPT课件
《模式识别与数据挖掘》配套PPT课件
科技成果转化项目进场交易前,评估备案环节需要准备哪些材料?_8.docx
科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。
人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核
人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核
跨境电商供应链管理(AIGC版)课件+教案+参考答案
跨境电商供应链管理(AIGC版)课件+教案+参考答案


