Supports the HTTP 1.1 protocol (the earlier version will not work with sites like Microsoft.Com or hosts using a single IP address for multiple domains).
Apr 27, 2001 -- Header is displayed to STDOUT and data is written to a file.
------------------
Home of the BASIC Gurus
www.basicguru.com
[This message has been edited by Dave Navarro (edited April 27, 2001).]
Apr 27, 2001 -- Header is displayed to STDOUT and data is written to a file.
Code:
'============================================================================== ' ' WEBGET v1.2 - Grab a file from a web site ' Copyright (c) 1999-2001 PowerBASIC, Inc. All Rights Reserved. ' '============================================================================== %port = 80 FUNCTION PbMain() AS LONG LOCAL buffer AS STRING LOCAL site AS STRING LOCAL file AS STRING LOCAL save AS STRING LOCAL temp AS STRING STDOUT "Webget v1.2 - Grab a file from a web site" STDOUT "Copyright (c) 1999-2001 PowerBASIC, Inc. All Rights Reserved." STDOUT "" IF LEN(COMMAND$) = 0 OR COMMAND$ = "/?" THEN STDOUT "Usage: webget url/file" STDOUT "" STDOUT " Ex: webget <A HREF="http://www.powerbasic.com/index.html"" TARGET=_blank>http://www.powerbasic.com/index.html"</A> EXIT FUNCTION END IF site = EXTRACT$(LTRIM$(LCASE$(COMMAND$),"http://"), "/") IF LEN(site) = 0 THEN STDOUT "Error! You must specify a web site." EXIT FUNCTION END IF file = TRIM$(MID$(COMMAND$, INSTR(LCASE$(COMMAND$), site) + LEN(site))) IF LEN(file) = 0 THEN STDOUT "Error! You must specify a file" EXIT FUNCTION END IF save = MID$(file, INSTR(-1, file, "/") + 1) IF LEN(save) = 0 THEN save = EXTRACT$(LTRIM$(site, "www."), ".") + ".html" END IF STDOUT "Connecting to " & site & " ..." TCP OPEN PORT %port AT site AS #1 TIMEOUT 30 IF ERR THEN STDOUT "Could not connect to " & site EXIT FUNCTION END IF STDOUT "Retrieving " & site & file & " to " & save & " ..." TCP PRINT #1, "GET " & file & " HTTP/1.1" TCP PRINT #1, "Accept: */*" TCP PRINT #1, "Accept-Language: en-us" TCP PRINT #1, "Host: " & site TCP PRINT #1, "Pragma: no-cache" TCP PRINT #1, "Referer: <A HREF="http://www.powerbasic.com/"" TARGET=_blank>http://www.powerbasic.com/"</A> TCP PRINT #1, "UserAgent: webget 1.2 (www.powerbasic.com) TCP PRINT #1, "" DO TCP RECV #1, 4096, buffer temp = temp & buffer LOOP WHILE LEN(buffer) buffer = REMAIN$(temp, $CRLF & $CRLF) temp = EXTRACT$(temp, $CRLF & $CRLF) ' ** Display the header information STDOUT temp ' ** Write the data section to a file OPEN save FOR BINARY AS #2 SETEOF #2 PUT$ #2, buffer CLOSE #2 TCP CLOSE #1 END FUNCTION
Home of the BASIC Gurus
www.basicguru.com
[This message has been edited by Dave Navarro (edited April 27, 2001).]
Comment