Page 2 of 2

Re: URL to Internet

Posted: Thu May 28, 2020 12:44 pm
by JackKelly
It did indeed work quite well. Thank you. I never would have thought to look in Rosetta for the sample code. Here's a working demo, to save others a bit of head scratching.

Code: Select all

URL$="http://tgftp.nws.noaa.gov/data/observations/metar/stations/KPHL.TXT"
FileName$="ReceivedData$"
ReturnCode=DownloadToFile(URL$, FileName$)
if  ReturnCode=0 then
    open FileName$ for input as #f
        FileText$ = input$(#f, LOF(#f))
    close #f
    print FileText$
else
    print "ReturnCode = "; ReturnCode
end if
print "Program Complete."
end
 
function DownloadToFile(urlfile$, localfile$)
    open "URLmon" for dll as #url
        calldll #url, "URLDownloadToFileA",_
            0 as long,_             'null
            urlfile$ as ptr,_       'url to download
            localfile$ as ptr,_     'save file name
            0 as long,_             'reserved, must be 0
            0 as long,_             'callback address, can be 0
            DownloadToFile as ulong '0=success
    close #url
end function

Re: URL to Internet

Posted: Thu May 28, 2020 1:09 pm
by guest
JackKelly wrote:
Thu May 28, 2020 12:44 pm

Code: Select all

URL$="http://tgftp.nws.noaa.gov/data/observations/metar/stations/KPHL.TXT"
That should be ftp:// rather than http:// surely? If it's also available via the HTTP protocol you should be able to use httpget$() which is a built-in function in Liberty BASIC 4.5 and is available in LBB via the lb45func.bas library.

And indeed I can confirm that this does work. Seems to me that you have been making a mountain out of a molehill (and the information you received that it was only available via FTP was at the very least misleading):

Code: Select all

print httpget$("http://tgftp.nws.noaa.gov/data/observations/metar/stations/KPHL.TXT")
end
'include lb45func.bas

Re: URL to Internet

Posted: Fri May 29, 2020 1:10 am
by JackKelly
Hmm. Both programs work regardless if the message is prefixed with http:// or ftp://. I guess I misunderstood that that the data was available only by FTP. Is this all a molehill? Over and out.

Re: URL to Internet

Posted: Fri May 29, 2020 12:55 pm
by guest
JackKelly wrote:
Fri May 29, 2020 1:10 am
Both programs work regardless if the message is prefixed with http:// or ftp://.
That's probably because the file is available via HTTP anyway. My understanding is that URLDownloadToFile will successfully download a file using FTP (so long as the URL starts ftp:// and there is no requirement for a username or password) but I would expect httpget$() to work only if it can be downloaded via HTTP (probably the specified protocol is ignored in that case). Obviously when httpget$() works it's far easier than any other solution, especially in LB 4.5.