hi!
Im trying to make something that compares 2 files. One of the files is
on the users computer....
The other is on a website!
Obviously what Im trying to do is compare the lastModified date, in
order to update the file on the users computer if neccessary.
Only problem is that I dont know how I can get the size of the file
online without downloading it first...
Any ideas?
Nick Vatamaniuc - 30 Sep 2006 03:55 GMT
Would the HTTP "Content-length" header line help you? Some servers
don't send that so sometime you wouldn't know ahead of time. But in
general you can use the urllib module and then the info() method of the
urllib.urlopen() handler.
Here is the magic:
------------------------------------
In [1]: import urllib
In [2]:
hand=urllib.urlopen('http://www.python.org/images/python-logo.gif')
In [3]: hand.info().dict['content-length']
Out[3]: '2549'
-------------------------------------
Cheers,
-Nick V.
> hi!
>
[quoted text clipped - 10 lines]
>
> Any ideas?
Andrew Thompson - 30 Sep 2006 04:12 GMT
..
>....in
> order to update the file on the users computer if neccessary.
WebStart can handle that (for data files, as well as classes)
for the user automatically and relatively painlessly - with a
progress dialog.
Andrew T.
tiewknvc9 - 30 Sep 2006 06:49 GMT
unfortunately Im trying to avoid webstart (I dont like the whole code
signing thing)
So I created a class... something like this to compare the file sizes
//get online file size
URL url;
URLConnection conn;
long lSizeOfOnlineFile = 0;
long lSizeClientFile = filClientFile.length();
System.out.println("\nSize of Client file: " + lSizeClientFile + "
" + filClientFile.getAbsolutePath());
try {
url = new URL(strRemoteFile);
conn = url.openConnection();
lSizeOfOnlineFile = conn.getContentLength();
if(lSizeOfOnlineFile < 0){
System.out.println("Could not determine file size.");
}else{
System.out.println("\nSize of Online file: " +
lSizeOfOnlineFile);
}
conn.getInputStream().close();
}
catch(Exception e) {
e.printStackTrace();
}
//compare and act if files modification date are different
if (filClientFile == null){
System.out.println("filClientFile = null");
}
if (lSizeOfOnlineFile != lSizeClientFile){
> ..
> >....in
[quoted text clipped - 5 lines]
>
> Andrew T.
Andrew Thompson - 30 Sep 2006 08:15 GMT
Please refrain from top-posting.
> unfortunately Im trying to avoid webstart (I dont like the whole code
> signing thing)
WebStart applications do *not* need to be signed if ..
- they don't require a 'trusted environment'
- (or) they use the inbuilt JNLP API to access things
like files, clipboard and printer.
Re engineering a normal 'full access' application to
work within the JNLP API's can be tricky, but is
worth investigating.
Andrew T.
Simon Brooke - 01 Oct 2006 08:34 GMT
> hi!
>
[quoted text clipped - 10 lines]
>
> Any ideas?
HTTP head request will get you the size and last changed date without
pulling the whole file.

Signature
simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
Wannabe a Web designer?
<URL:http://userfriendly.org/cartoons/archives/97dec/19971206.html>
Chris Uppal - 01 Oct 2006 10:30 GMT
> HTTP head request will get you the size and last changed date without
> pulling the whole file.
And sometimes the server actually obeys the HTTP spec and sends back the
correct information...
-- chris
(Actually, they often do -- but it's not something to rely on)