www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to check for internet connectivity and download file?

reply Tyro[a.c.edwards] <nospam home.com> writes:
I've used Burton Radons' "urllib" in the past to get download files from the
internet, however the library has atrophied and can no longer be used with DMD
v2.029 (not how long it's been this way because I haven't tried to compile it
since 2006).

I'm wondering if someone could point me to an example of how to check for
internet connectivity and if available download the latest version of a given
file.

Thanks in advance.
Andrew
Apr 26 2009
next sibling parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
Well, checking for internet connectivity is a tricky and 
operating-specific thing.

Would you rather check for connectivity with a specific host?  I gather 
that would be more than appropriate for what you're wanting.

Are you wanting to download over HTTP, or a different protocol?  If over 
HTTP, there are a ton of libraries that may be useful to you, and 
there's also building your own HTTP request (which is actually pretty 
trivial.)

If you're using Tango, it has classes in it for these things.

-[Unknown]


Tyro[a.c.edwards] wrote:
 I've used Burton Radons' "urllib" in the past to get download files from the
internet, however the library has atrophied and can no longer be used with DMD
v2.029 (not how long it's been this way because I haven't tried to compile it
since 2006).
 
 I'm wondering if someone could point me to an example of how to check for
internet connectivity and if available download the latest version of a given
file.
 
 Thanks in advance.
 Andrew
Apr 26 2009
parent reply Tyro[a.c.edwards] <nospam home.com> writes:
Unknown W. Brackets Wrote:

 Well, checking for internet connectivity is a tricky and 
 operating-specific thing.
 
 Would you rather check for connectivity with a specific host?  I gather 
 that would be more than appropriate for what you're wanting.
This should do just fine. Afterall it would do no good if I have connectivity but cannot reach the intended host.
 Are you wanting to download over HTTP, or a different protocol?  If over 
 HTTP, there are a ton of libraries that may be useful to you, and 
 there's also building your own HTTP request (which is actually pretty 
 trivial.)
I'm trying to download over both FTP and HTTP. Not sure if the same process is applicable to both protocols but I'm assuming not.
 If you're using Tango, it has classes in it for these things.
Unfortunately I haven't played with Tango many years now and got away from D1 as soon D2 forked back in 2007.
 -[Unknown]
 
 
 Tyro[a.c.edwards] wrote:
 I've used Burton Radons' "urllib" in the past to get download files from the
internet, however the library has atrophied and can no longer be used with DMD
v2.029 (not how long it's been this way because I haven't tried to compile it
since 2006).
 
 I'm wondering if someone could point me to an example of how to check for
internet connectivity and if available download the latest version of a given
file.
 
 Thanks in advance.
 Andrew
Apr 26 2009
parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
If you want both HTTP and FTP, it's definitely worth using a library for 
it.  There are a lot of options, but almost all of them are out of date 
I suppose for 2.x...

I've always hated curl, but you might look at how hard it is to get/make 
d headers for it.  This might work fine for you.

HTTP is relatively easy.  You can see a sample in 
dmd/samples/d/htmlget.d.  This isn't exactly a right example, because it 
completely ignores Transfer-Encoding, but if you search and replace 
HTTP/1.1 with HTTP/1.0, it should be usable.... although the check for 
</html> is an ugly hack and 100% wrong.

FTP is more work.  You have to send and receive commands, so it's 
slower.  It's also worth maintaining state if you download more than one 
file from the same server.

I have a library that does it, but unfortunately it's for 1.x.  I'm 
planning to update it, but I won't be able to for a little while.  I 
could explain what you need to do if you want to mess with the socket 
stuff...

But again, it's complicated enough it's not a good idea to do it 
yourself imho unless you like reading RFCs (I do, but I'm a strange one.)

-[Unknown]


Tyro[a.c.edwards] wrote:
 Unknown W. Brackets Wrote:
 
 Well, checking for internet connectivity is a tricky and 
 operating-specific thing.

 Would you rather check for connectivity with a specific host?  I gather 
 that would be more than appropriate for what you're wanting.
This should do just fine. Afterall it would do no good if I have connectivity but cannot reach the intended host.
 Are you wanting to download over HTTP, or a different protocol?  If over 
 HTTP, there are a ton of libraries that may be useful to you, and 
 there's also building your own HTTP request (which is actually pretty 
 trivial.)
I'm trying to download over both FTP and HTTP. Not sure if the same process is applicable to both protocols but I'm assuming not.
 If you're using Tango, it has classes in it for these things.
Unfortunately I haven't played with Tango many years now and got away from D1 as soon D2 forked back in 2007.
 -[Unknown]


 Tyro[a.c.edwards] wrote:
 I've used Burton Radons' "urllib" in the past to get download files from the
internet, however the library has atrophied and can no longer be used with DMD
v2.029 (not how long it's been this way because I haven't tried to compile it
since 2006).

 I'm wondering if someone could point me to an example of how to check for
internet connectivity and if available download the latest version of a given
file.

 Thanks in advance.
 Andrew
Apr 27 2009
parent "Tyro[a.c.edwards]" <nospam home.com> writes:
On 4/27/2009 5:14 PM, Unknown W. Brackets wrote:
 If you want both HTTP and FTP, it's definitely worth using a library for
 it. There are a lot of options, but almost all of them are out of date I
 suppose for 2.x...

 I've always hated curl, but you might look at how hard it is to get/make
 d headers for it. This might work fine for you.
Apparently Kenneth Bogert did some work on curl a while back. cURL happens to host it on their site so I'll give it a shot.
 HTTP is relatively easy. You can see a sample in
 dmd/samples/d/htmlget.d. This isn't exactly a right example, because it
 completely ignores Transfer-Encoding, but if you search and replace
 HTTP/1.1 with HTTP/1.0, it should be usable.... although the check for
 </html> is an ugly hack and 100% wrong.
I'll take a look at it. I'm sure there is something there worth learning.
 FTP is more work. You have to send and receive commands, so it's slower.
 It's also worth maintaining state if you download more than one file
 from the same server.

 I have a library that does it, but unfortunately it's for 1.x. I'm
 planning to update it, but I won't be able to for a little while. I
 could explain what you need to do if you want to mess with the socket
 stuff...
I'm virtually hopeless when it comes to these things so will happily accept assistance in whatever form I can get it. If you are willing to explain I will graciously accept the lesson.
 But again, it's complicated enough it's not a good idea to do it
 yourself imho unless you like reading RFCs (I do, but I'm a strange one.)
Can't say I have much fondness for RFCs but over time that might change. As for being a strange one... well I'm as strange as they come so I will not be passing judgment anytime soon.
 -[Unknown]
Apr 27 2009
prev sibling parent BLS <windevguy hotmail.de> writes:
Tyro[a.c.edwards] wrote:
 I've used Burton Radons' "urllib" in the past to get download files from the
internet, however the library has atrophied and can no longer be used with DMD
v2.029 (not how long it's been this way because I haven't tried to compile it
since 2006).
 
 I'm wondering if someone could point me to an example of how to check for
internet connectivity and if available download the latest version of a given
file.
 
 Thanks in advance.
 Andrew
What about PING ? Björn
Apr 27 2009