473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

get file details for HTTP location

Hi, is there any way of getting details (such as last modified/created
date/time) of a file located on the web?

E.g I'd like to know when the file "http://www.myWebSite.com/
update.txt" was last created/modified.

Cheers,

Tony.

Sep 18 '07 #1
8 6412
Hello, ba********@hotmail.com!

With general HTTP access there is no way to get these values.
If that file will be located on FTP server then some of the mentioned
properties will be available.

If only HTTP access is available, you can add special page on the server
that will return update.txt upon request and specify necessary attributes in
the HTTP headers.

HTH
--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Tue, 18 Sep 2007 10:49:47 -0000:

btHi, is there any way of getting details (such as last
btmodified/created date/time) of a file located on the web?

btE.g I'd like to know when the file "http://www.myWebSite.com/
btupdate.txt" was last created/modified.

btCheers,

btTony.
Sep 18 '07 #2
Vadym Stetsiak wrote:
Hello, ba********@hotmail.com!

With general HTTP access there is no way to get these values.
This is incorrect. Normal webservers will return an HTTP header
Last-Modified that contains this information.

To the OP: See "14.29 Last-Modified" in
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for information
on what to expect in response.

Some webservers may not respond properly with Last-Modified, so it's
best to ensure your target uses proper headers before relying on it (and
even then, it's subject to change).

Chris.
Sep 18 '07 #3
On Sep 18, 10:48 pm, Chris Shepherd <c...@nospam.chsh.cawrote:
Vadym Stetsiak wrote:
Hello, baker_t...@hotmail.com!
With generalHTTPaccess there is no way to get these values.

This is incorrect. Normal webservers will return anHTTPheader
Last-Modified that contains this information.

To the OP: See "14.29 Last-Modified" inhttp://www.w3.org/Protocols/rfc2616/rfc2616-sec14.htmlfor information
on what to expect in response.

Some webservers may not respond properly with Last-Modified, so it's
best to ensure your target uses proper headers before relying on it (and
even then, it's subject to change).

Chris.
Hi,

I am tryng to write a windows service that will retrieve csv files and
other files over HTTP. I only want to get those files that have been
updated recently. Considering the discussion above do you think this
is an unreliable way to go? Maybe I should try look at ftp?

I cant seem to get the last-modified property off the header... here
is some sample code I am testing:

Any help would be greatly appreciated... thanks!

************************************************** ************************************************** ************************************************** *******

System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://
uri/TestHTML.htm");
string last = req.Headers["If-Modified-Since"];
IEnumerator cacheEnum = req.Headers.GetEnumerator();
while (cacheEnum.MoveNext())
{
string strKey = cacheEnum.Current.ToString();
}

Sep 19 '07 #4
On Sep 19, 9:16 am, gwell <gavincolw...@gmail.comwrote:
I cant seem to get the last-modified property off the header... here
is some sample code I am testing:

Any help would be greatly appreciated... thanks!
************************************************** ************************************************** ************************************************** *******
>
System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://
uri/TestHTML.htm");
string last = req.Headers["If-Modified-Since"];
IEnumerator cacheEnum = req.Headers.GetEnumerator();
while (cacheEnum.MoveNext())
{
string strKey = cacheEnum.Current.ToString();

}
You need to *add* the If-Modified-Since header yourself. The idea is
that you tell the server when you last fetched the data, and it can
either give you back the data or tell you that it hasn't changed.

Jon

Sep 19 '07 #5
Hello, gwell!

Ftp can be a better option here.
Another way, if you have access to the remote HTTP server (where CSVs are
hosted) and that server has, say, ASP.NET. Then you can code ASP.NET
web page that will return requested file along with necessary headers.

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Wed, 19 Sep 2007 01:16:47 -0700:

gOn Sep 18, 10:48 pm, Chris Shepherd <c...@nospam.chsh.cawrote:
>Vadym Stetsiak wrote:
>>Hello, baker_t...@hotmail.com!
>>With generalHTTPaccess there is no way to get these values.
>This is incorrect. Normal webservers will return anHTTPheader
Last-Modified that contains this information.
>To the OP: See "14.29 Last-Modified"
inhttp://www.w3.org/Protocols/rfc2616/rfc2616-sec14.htmlfor
information on what to expect in response.
>Some webservers may not respond properly with Last-Modified, so it's
best to ensure your target uses proper headers before relying on it
(and even then, it's subject to change).
>Chris.
gHi,

gI am tryng to write a windows service that will retrieve csv files
gand other files over HTTP. I only want to get those files that have
gbeen updated recently. Considering the discussion above do you think
gthis is an unreliable way to go? Maybe I should try look at ftp?

gI cant seem to get the last-modified property off the header... here
gis some sample code I am testing:

gAny help would be greatly appreciated... thanks!

g************************************************* *********************
g************************************************* *********************
g*****************

gSystem.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://
guri/TestHTML.htm");
gstring last = req.Headers["If-Modified-Since"];
gIEnumerator cacheEnum = req.Headers.GetEnumerator();
gwhile (cacheEnum.MoveNext())
g{
g string strKey = cacheEnum.Current.ToString();
g}

Sep 19 '07 #6
gwell wrote:
I am tryng to write a windows service that will retrieve csv files and
other files over HTTP. I only want to get those files that have been
updated recently. Considering the discussion above do you think this
is an unreliable way to go? Maybe I should try look at ftp?
Here's the thing. I think FTP could be a good way to go if you had to do
this in multiple locations, where reliability may be in question. The
problem is most hosts nowadays do properly return the Last-Modified
header -- at the very least, all installs of Apache and IIS CAN return
the Last-Modified header, and do by default.

The major con with using an FTP connection is that you're doing quite a
bit more work to do what you could do with a simple HTTP request. The
overhead might be minimal, but in code, tracking FTP sites, logins,
etc., that's going to be far and away more work than simply tracking the
URL and checking its Last-Modified header.

Now, given your goal here of grabbing remote files via a service, I
think you should definitely stick to HTTP until such time as it becomes
an issue for you. Last-Modified is part of the RFC, so RFC-friendly
webservers will understand what you're looking for (which, just with the
two mentioned above accounts for something like 96%+ of all webservers
in use publicly on the Internet), and it's fairly trivial to implement.
I cant seem to get the last-modified property off the header... here
is some sample code I am testing:

Any help would be greatly appreciated... thanks!
[...]

Jon's response already covered the code stuff.

Chris.
Sep 19 '07 #7
On Sep 19, 10:21 pm, Chris Shepherd <c...@nospam.chsh.cawrote:
gwell wrote:
I am tryng to write a windows service that will retrieve csv files and
other files overHTTP. I only want to get those files that have been
updated recently. Considering the discussion above do you think this
is an unreliable way to go? Maybe I should try look at ftp?

Here's the thing. I think FTP could be a good way to go if you had to do
this in multiple locations, where reliability may be in question. The
problem is most hosts nowadays do properly return the Last-Modified
header -- at the very least, all installs of Apache and IIS CAN return
the Last-Modified header, and do by default.

The major con with using an FTP connection is that you're doing quite a
bit more work to do what you could do with a simpleHTTPrequest. The
overhead might be minimal, but in code, tracking FTP sites, logins,
etc., that's going to be far and away more work than simply tracking the
URL and checking its Last-Modified header.

Now, given your goal here of grabbing remote files via a service, I
think you should definitely stick toHTTPuntil such time as it becomes
an issue for you. Last-Modified is part of the RFC, so RFC-friendly
webservers will understand what you're looking for (which, just with the
two mentioned above accounts for something like 96%+ of all webservers
in use publicly on the Internet), and it's fairly trivial to implement.
I cant seem to get the last-modified property off the header... here
is some sample code I am testing:
Any help would be greatly appreciated... thanks!

[...]

Jon's response already covered the code stuff.

Chris.
Hi,

Thanks for all the feedback. I have just got a proof of concept
working using HTTP and I'm going to start building the windows
service. I found the following article useful:

http://www.clariusconsulting.net/blo.../30/29105.aspx

Here is my updated code that I will work with -

Thanks for all your comments... much appreciated!

************************************************** ************************************************** ************************************************** ***

// Create a request for the URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://uri/
TestHTML.htm");

// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
request.IfModifiedSince = DateTime.Parse("23-07-2007");

try
{
using (WebResponse response = request.GetResponse())
{
// Do something if the resource has changed.
}
}
catch (WebException wex)
{
HttpWebResponse httpResponse = wex.Response as HttpWebResponse;
if (httpResponse.StatusCode == HttpStatusCode.NotModified)
{
// resource was not modified.
}
// Something else happened. Rethrow or log.
throw;
}

Sep 20 '07 #8
Fantastic stuff! I managed to construct the following code which gives
me the last modified date time:

HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://www.teslaeurope.com/
default.htm");

// If required by the server, set the credentials.
//request.Credentials =
CredentialCache.DefaultCredentials;
//request.IfModifiedSince = DateTime.Parse("01-01-1990");

try
{
using (WebResponse response = request.GetResponse())
{
string lastModified = response.Headers["Last-
Modified"].ToString();
}
}
catch (WebException wex)
{
....

Oct 11 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Joseph Oget | last post by:
If I use the code below in a VB.NET form, even if the file exists, and is then executed, the Else statement produces the "Sorry cannot find the File " error message. The MessageBox.Show(...
3
by: wschaub | last post by:
We need to inject information (i.e. server details from where a signed file was downloaded) into a signed file, without breaking the signature or integrity of a signed file. Apparently there are...
3
by: Jim | last post by:
Hi, I have an assembly and it's satellite in my GAC. I have referenced the DLLs in my project (from the same location where I added it to the GAC). CopyLocal is set false. When I run the...
8
by: Krishnan Margabandhu | last post by:
I'm writing a Pocket PC app that will run when a device is first powered on. I want this program to get some data from the user and invoke a CAB file to install a software on the device. How do I...
1
by: brian.newman | last post by:
I'm trying to link a gridview to another gridview in a Master-Details architecture. But the Details list isn't filtering like it is suppossed to. It will show all items on page load and it won't...
4
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing....
12
by: glennanthonyb | last post by:
Hi The company I work for has finally woken up to data security on our field laptops. I'm writing something in C# that will allow remote deletion of sensitive data and I don't believe...
4
by: David | last post by:
Hi I'm using this code to import data from an excel spreadsheet: DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "tblStudents", _ "\\Egusersrv\Staff - Shared Work\PE Teach &...
3
by: grant | last post by:
Good day, How do I open a text file from the applications install location? I am currently opening a text file using "StreamReader sr = new StreamReader("DB.txt");" and then reading from that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.