Re: Download files from the web [message #86938 is a reply to message #86936] |
Mon, 16 December 2013 05:24   |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den måndagen den 16:e december 2013 kl. 13:46:00 UTC+1 skrev David Fanning:
> Mats Löfdahl writes:
>
>> I need to make an idl program download a couple of text files from the web. I found the webget() function from astrolib, now also distributed with idl, see http://www.exelisvis.com/docs/webget.html
>
>> My problem with that is that I don't know if the download succeeded. If I give a non-existing URL, I get the 404 error page downloaded and everything looks fine. If I set the COPYFILE keyword to some local file name, the file gets stored there and instead of the file contents, the return value is a scalar long. The web page does not say how this number should be interpreted but it seems to be unity whether or not the URL was really valid.
>
>> I guess I could search the downloaded file for some variation of "404 - Page not found" but I don't know how much that string varies from web server to web server. And it seems a hassle anyway.
>
>> I had a look at http://www.exelisvis.com/docs/socket.html, too. Promisingly it has an ERROR keyword but I don't understand how to tell it which file I want. Seems possible only to specify the host but not which file on the host. Near the bottom of the socket.html page there are two links to pages that promise to tell me how to read web pages and access ftp servers through socket, but when I click on them I get "Article does not exist or Permission Denied" errors.
>
>> So, how does one make idl download files from the web - and tell you if it worked?
>
> It seems like FILE_TEST might be helpful.
I'm not sure if you mean I should use it locally after downloading to see if the file was downloaded or remotely to see if the file is there before I try to download it.
If the locally, it would find *a* file also if that file is only partially downloaded or if it is a 404 error html file.
If the remotely, I guess it is nice to know that the file exists on the server but that does not guarantee that I will be able to download it. And, although I see there is a SOCKET keyword that I didn't know about, I still don't know how to specify the remote file with the socket command.
|
|
|