"Webrequestmethods. FTP. downloadfile cannot retain the last modification time of the file" SOLUTION

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.