C# FtpWebRequest File version check

2019-08-18 05:21发布

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?

1条回答
时光不老,我们不散
2楼-- · 2019-08-18 05:24

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

查看更多
登录 后发表回答