Webrequestmethods. FTP. downloadfile cannot retain the last modification time of the file. In webrequestmethods. FTP. listdirectorydetails, only the day of the month is used, and the problem cannot be solved through analysis.
To retain the last modification time of the file, we need to manually obtain the time and then set it. The Code is as follows:
Public static datetime getdatetimestamp (string remotefile, bool usessl, string username, string password)
{
Uri uri = new uri (remotefile );
Ftpwebrequest request = (ftpwebrequest) webrequest. Create (URI );
Request. Credentials = new networkcredential (username, password );
Request. method = webrequestmethods. FTP. getdatetimestamp;
Request. usebinary = true;
Request. usepassive = false;
If (usessl)
{
// The following four lines of code are used to support displaying SSL (explicit it SSL). ftpwebrequest in. net2.0 does not support
// Implicit SSL (implicit SSL ). If you do not need SSL, just comment them out.
Request. enablessl = true;
Servicepointmanager. servercertificatevalidationcallback =
Delegate (Object OBJ, x509certificate certificate, x509chain chain, sslpolicyerrors errors)
{Return true ;};
}
Ftpwebresponse response = (ftpwebresponse) request. getresponse ();
Return response. lastmodified;
}