C# FtpWebRequest File version check

谁都会走 提交于 2019-12-25 01:22:42

问题


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:


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



来源:https://stackoverflow.com/questions/2140704/c-sharp-ftpwebrequest-file-version-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!