How to check for internet connectivity and download file?

Unknown W. Brackets unknown at simplemachines.org
Mon Apr 27 01:14:07 PDT 2009


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
> 


More information about the Digitalmars-d-learn mailing list