C#FtpWebRequest文件版本检查 [英] C# FtpWebRequest File version check

查看:217
本文介绍了C#FtpWebRequest文件版本检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用C#FtpWebRequest来下载文件。我不想下载,除非下载站点中的文件版本大于当前文件版本。如何在远程服务器上验证/获取文件版本?

解决方案

 
.exe和.dll文件具有版本信息,可以使用
FileVersionInfo .. ::。GetVersionInfo()读取该版本信息。文本文件没有版本信息。
此外,为了阅读此版本信息,您必须将文件
下载到临时位置。



或者,您也可以使用文件的LastModifiedDate来检查它是否是最近
。这将适用于任何类型的文件,可以直接在FTP
站点上完成,无需下载文件:

  string requestUriString = BuildRequestUriString(ServerName,Path,fileName); 
FtpWebRequest aRequest =(FtpWebRequest)WebRequest.Create(requestUriString)
aRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp;
...

使用(FtpWebResponse aResponse =(FtpWebResponse)aRequest.GetResponse())
{
return aResponse.LastModified;
}


I am trying to use C# FtpWebRequest to download a file. I dont want to download unless the file version in the download site is greater than the current file version. How do i verify/get the file version on the remote server?

解决方案

Only .exe and .dll files have version info, which can be read by using
FileVersionInfo..::.GetVersionInfo(). Text files do not have version info. 
Also, in order to read this version info, you'll have to download the file 
to a temp location.

Alternately, you can use the LastModifiedDate of the file to check if it is more recent. That will work for any type of file and can be done directly at the FTP site w/o downloading the file:

string requestUriString = BuildRequestUriString(ServerName, Path, fileName);
FtpWebRequest aRequest = (FtpWebRequest) WebRequest.Create(requestUriString)
aRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp;
...

using (FtpWebResponse aResponse = (FtpWebResponse) aRequest.GetResponse())
{
  return aResponse.LastModified;
}

这篇关于C#FtpWebRequest文件版本检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆