开发者

C# - Downloading files - Only download file if local filestamp is older than on server

开发者 https://www.devze.com 2023-03-15 04:11 出处:网络
How is it possible to download files from a server, and have C# only download the file if the timestamp on the local file is older than the file timestamp o开发者_开发问答n the server? In this case th

How is it possible to download files from a server, and have C# only download the file if the timestamp on the local file is older than the file timestamp o开发者_开发问答n the server? In this case the two files have the same name, extension, etc...

For example file in web server:

http://www.test.com/test.txt

File on local computer:

C:\test.txt


You can use the HTTP If-Modified-Since header field to download a file only when it's newer than a given timestamp:

  1. Determine the LastWriteTime the local file.
  2. Send the HttpWebRequest with the IfModifiedSince property set to the LastWriteTime.
  3. If the remote file has been modified since the header value, a 200 OK response is returned as usual. Otherwise, a 304 NotModified response is returned, indicating that the remote file has not been modified since the header value.

Note that a 304 NotModified response causes a WebException to be thrown. See: Using If-Modified-Since in HTTP Requests.


See this link: http://www.codeguru.com/csharp/.net/net_general/internet/print.php/c16073

Basically your looking for a "conditional get" The link above should get you started.

0

精彩评论

暂无评论...
验证码 换一张
取 消