mIRC Home    About    Download    Register    News    Help

Print Thread
#225723 08/09/10 04:42 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Hi there,

Say I want to use sockets to download a text file like versions.txt what is the most reliable way to check the file has completed downloading?

I can use sockets to read the file etc, but want a reliable way to check that the download has completed!

I don't want to use the sockclose event as the socket in theory could close before the file has been downloaded. I guess I am looking for something similar to 200 ok response etc.

Any help or insights would be greatly appreciated.

Regards


Newbie
HaleyJ #225724 08/09/10 04:47 PM
Joined: Nov 2009
Posts: 81
V
Babel fish
Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
see Content-Length HTTP header, and when $file().size == content-length, then file downloaded.

Voglea #225897 12/09/10 07:40 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Originally Posted By: Voglea
see Content-Length HTTP header, and when $file().size == content-length, then file downloaded.


Just tested it and it does not work. I checked and $file().size differs from Content-length:


Newbie
HaleyJ #225899 12/09/10 09:20 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
How much is it off by? Are you saving the HTTP headers in the file? Are you writing the file using binary variables? Let's see your code.

HaleyJ #225901 12/09/10 10:56 PM
Joined: May 2007
Posts: 37
C
Ameglian cow
Offline
Ameglian cow
C
Joined: May 2007
Posts: 37
if you're interested, i wrote a script to download any file here: http://forum.swiftirc.net/viewtopic.php?f=34&t=18010

Collective #225920 13/09/10 10:33 AM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
I am not downloading the headers. Just the file. I parse the headers out.

It is off by 82. The Content-Length: is 6747 and the file().size returns 6829



Newbie
HaleyJ #225923 13/09/10 10:57 AM
Joined: May 2007
Posts: 37
C
Ameglian cow
Offline
Ameglian cow
C
Joined: May 2007
Posts: 37
It's quite possible that the server is responding with chunked data. Try changing HTTP/1.1 to HTTP/1.0 and see if that resolves your problem.

HaleyJ #225925 13/09/10 11:27 AM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Also, make sure you're not writing anything to file when the value of the sockread is $null.

5618 #225931 13/09/10 12:39 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Originally Posted By: 5618
Also, make sure you're not writing anything to file when the value of the sockread is $null.


I have made sure of that, thanks


Newbie
Chessnut #225932 13/09/10 12:42 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Originally Posted By: Chessnut
It's quite possible that the server is responding with chunked data. Try changing HTTP/1.1 to HTTP/1.0 and see if that resolves your problem.


It has not resolved the problem. Same results as in my previous post.


Newbie
HaleyJ #225939 13/09/10 10:05 PM
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
A good thing to do would have been to show your code in your first post, or at least when it was explicity asked..
I'm sure you understand that people can't really help you with this just by guessing


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
HaleyJ #225995 15/09/10 04:08 PM
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
I have a socket updater for my scripts. I have a version.txt sort of file uploaded on my server. I have text that says when it starts and ends so I didn't have to code to get past the headers. Less code, more direct. When reading this text file with a socket I found issues reading the last line. It was so long ago I can't remember them, but that is why I added the hyphen as the last line. My code looks for:

$1 = update, $2 = end, and knows its the end of the file.

My file looks like this.

update start
filename.mrc version
d_filename.mrc description
p_filename.mrc path
update end
-


Link Copied to Clipboard