“WebRequestMethods.Ftp.DownloadFile不能保留文件最后修改时间”的解决方法
2008-09-12 16:10
701 查看
WebRequestMethods.Ftp.DownloadFile不能保留文件最后修改时间这个属,WebRequestMethods.Ftp.ListDirectoryDetails中只有月日时分,通过分析它也不能解决问题。
要想保留文件最后修改时间我们需要手动获取时间,然后进行设置。代码如下:
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)
{
//下面4行代码用于支持显示SSL(explicit SSL),.NET2.0中的FtpWebRequest不支持
//隐式SSL(implicit SSL)。如果不用SSL,注释掉它们即可。
request.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ return true; };
}
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
return response.LastModified;
}
要想保留文件最后修改时间我们需要手动获取时间,然后进行设置。代码如下:
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)
{
//下面4行代码用于支持显示SSL(explicit SSL),.NET2.0中的FtpWebRequest不支持
//隐式SSL(implicit SSL)。如果不用SSL,注释掉它们即可。
request.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ return true; };
}
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
return response.LastModified;
}
相关文章推荐
- “WebRequestMethods.Ftp.DownloadFile不能保留文件最后修改时间”的解决方法
- FtpWebRequest UploadFile返回"The underlying connection was closed: The server committed a protocol violation."解决方法
- python笨办法解决zipfile解压会改变文件最后修改时间的问题
- 读取文件的最后修改时间的方法
- Android webview Input type=file 文件上传 解决方法
- pb9获取文件创建时间、最后修改时间及设置最后修改时间的方法
- 郁闷N天了,IDFTP发生10054错误后无法继续上传文件,重新创建IDFTP后发生错误:550 cannot create file。请教解决方法
- 异常-----springmvc + ajaxfileupload解决ajax不能异步上传图片的问题。java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.
- IE input file隐藏不能上传文件解决方法(转载)
- 修改系统时间导致myeclipse不能自动发布的解决方法
- cs文件中不能继承System.Web.UI.Page问题的解决方法
- .NET的file文件上传控件使用方法 修改web.config文件上传大文件
- .NET的file文件上传控件使用方法 修改web.config文件上传大文件
- JBuilder2006不能自动编译.class文件在WEB-INF/CLASSES文件下的解决方法
- ftp传文件遇到不能传中文的解决方法
- windows mobile 6.3 FTP FtpGetFileSize 取得文件大小为0xFFFFFFFF 解决方法
- 修改http请求文件为本地文件的一种方法:hook InternetReadFile 和 HttpOpenRequest
- VC URLDownloadToFile 不能下载中文路径文件的解决办法
- Win7系统修改hosts文件不能保存的解决方法
- C#获取ftp文件最后修改时间