[Tutor] FW: Retrieving a text file with a URL call

Blake Winton bwinton@tor.dhs.org
Fri, 6 Aug 1999 08:46:37 -0400 (EDT)


> We have recently experienced the need to pull down text files created
> with a URL call over the Internet and save them to a predetermined
> location on the users hard drive.  We have found that using DDE we can
> complete this task with users that have NetScape; however, IE does not
> support the parameter to specify where the file needs to be saved.

Have you tried sending a Content-Type header?
It would look like "Content-Type: inline;filename=pathtofile"
(I'm not sure whether or not you can put a path in, but it's worth a
try.)

> Let me know if it sounds like python is the tool that I need to put
> together a piece of code that could be distributed to our users and
> called from their application to retrieve this file and save it to
> their hard drive.

Odd that you would mention this.  I've hacked up a couple of scripts
that do pretty much exactly that.

The relevant parts are:

#!/usr/bin/python

# Set up the proxy server for Sympatico.
# (They don't let us out on port 80).
import os
os.environ['http_proxy']="http://choco.bellglobal.com:80/"

import urllib

# Gets an arbitrary url.  I forget why I did this...
def geturl( url ):
    session = urllib.urlopen( url )
    return session

# Get objects for the two files.
urlfile = geturl( "http://tor.dhs.org/~bwinton/urls" )
localfile = open( "whateverfilenameyouwant.txt", "w" )

for line in urlfile.readlines():
    localfile.write( line )
# I think this whole for loop could also be written as
# localfile.write( urlfile.read() )

Hope this helped,
Blake.