tcpcmd.getURL
Retrieve WWW Docs Without a Browser!

tcpcmd.getURL is one of the most useful tcpcmd verbs. You can do a lot of powerful stuff slinging html files 'round the net!

Let's use getURL to retrieve the page you're reading right now and store it on your hard disk:

tcpcmd.getURL("http://www.erols.com/asg/tcpcmdDocs/getURL.html", file.getSystemDisk() + "Desktop Folder:")
« "HTTP/1.0 200 OK\rDate: Tue, 15 Oct 1996 22:58:58 GMT\rServer: Apache/1.1.1\rContent-type: text/html\rContent-length: 857\rLast-modified: Sun, 13 Oct 1996 16:39:37 GMT"

The file "getURL.html" will appear on your desktop. You can drag it onto your browser to have it rendered.

getURL not only saves the content in the file, but it also returns the http header as a string. The header is shown in the comment line below our example call above. The http header is always returned for http urls.

You don't have to store pages on disk. You can retrieve a URL and store it in Frontier's database. Suppose you have a wpText item at scratchpad.htmlDoc.

tcpcmd.getURL("http://www.erols.com/asg/tcpcmdDocs/getURL.html", @scratchpad.htmlDoc)

will store the header and contents of that file in scratchpad.htmlDoc:

If you want, you can ask getURL to retrieve the header and the file content and return them together as a string:

scratchpad.x = tcpcmd.getURL("http://www.erols.com/asg/tcpcmdDocs/getURL.html")

The http header and content will be stored in a character string at scratchpad.x.

You could then extract any additional urls from that page and pass them to getURL if you wanted to.

getURL works with ftp urls, too! You can download a file from ftp.scripting.com like this:

tcpcmd.getURL("ftp://ftp.scripting.com/userland/finderAliases.sit.hqx")

Notice that we didn't specify a destination for where to store the file. When no destination is specified, the file will have the same name as the source file in be copied into the root directory of the boot drive.

We can download the file into our favorite download folder like this:

tcpcmd.getURL("ftp://ftp.scripting.com/userland/finderAliases.sit.hqx", "hard drive:desktop folder:Recent Downloads:")

getURL can fetch gopher urls:

tcpcmd.getURL("ftp://ftp.scripting.com/userland/finderAliases.sit.hqx")

The syntax of tcpcmd.getURL is:

tcpcmd.getURL (url, [,saveAs] [,proxy] [,timeout] [,bufSize])

where

  • url

    is a string containing the url you want to retrieve. This version of tcpcmd only supports http://, ftp://, and gopher:// urls.

    "http://www.scripting.com/frontier/"

  • saveAs
    an optional parameter that indicates where to store the retrieved file and can be one of the following:

    • a string that will be interpreted to be a valid path string to the file or folder where the contents will be saved. If only a folder is specified, the file name will be the same as the file name in the url.

    • an address to a string or wpText object in the Frontier database that will receive:
      • for an http url, the content.
      • for an ftp url that specifies a directory, the directory listing.
      • for an gopher url, the result of the gopher command.

      "my drive:downloads:"

      "my drive:my folder:aSpecificFile"

      @scratchpad.myWPtextObject

      @scratchpad.directoryListing

      The saveAs parameter can be omitted. This affects the action of getURL depending on the type of url being fetched:

      • for an http url, the header and content and will be returned as a string.
      • for an ftp url:
        • If the url specifies a file, then the file will be saved in the root directory of the boot drive, with the same name as that of the source file.
        • If the url specifies a directory, then the directory listing will be returned as a string.
      • for a gopher url, the gopher results will be returned as a string.
  • proxy
    an optional string that, if included, contains the ip address for a proxy server.

    "199.209.15.77"

    "199.209.15.77:33222"

  • timeout
    an optional number containing the number of seconds getURL will wait at each step in the sending and receiving process before it gives up and returns to the caller. The default timeout used is defined in tcpcmd.timeouts.http.

  • bufSize

    an optional number specifying the size of the buffer Frontier should use when downoading a file. The default value is 5120 bytes. Please note that this version of tcpcmd will use up to twice the amount specified in bufSize since it must use some Frontier string verbs.

Returns

  • a string containing the http header (if an http url is used), the directory listing (if an ftp directory url is used), or the results of the gopher command (if a gopher url is used).
  • true if an ftp file url is used (same as tcpcmd.ftp.download)
  • a script error if there is an error contacting the host or any other communications error.

Restrictions

Proxy support is not available for ftp urls at this time.


This page was last built on 8/1/98; 10:28:42 PM ET by Alan German, asg@erols.com. At the moment, I am using Macintosh OS to work on this website. The "Electric Cactus" graphic is based on original artwork owned by UserLand Software and is used with their permission.