downloading cgi advice

Jeff Shipman shippy at nmt.edu
Thu May 9 18:38:46 EDT 2002


I've got a cgi which handles downloading
files to a person's computer. Files of
type .tar.gz and .exe go through this CGI.
These are some snippets I have from the
program:

    # Determine size of file
    try:
       s = os.stat(BASEDIR+'/'+loc)
       size = int(s[6])
    except OSError:
       errmsg('Couldn\'t stat() file!')
    except:
       errmsg('Unexpected error while calling stat()!')


    # Initiate download
    logline = 'Host: %s - Initiating download for file %s of %d bytes.' \
              % (gethost(), loc, size)
    log(logline)
    print 'Content-disposition: attachment; filename=%s\n'\
          'Content-type: application/octet-stream\n'\
          'Content-length: %d\n' % (loc, size)
    try:
       file = open(BASEDIR+'/'+loc, 'rb')
    except:
       errmsg('Couldn\'t access download file!')

    sys.stdout.write(file.read(size))
    file.close()

This seems to work fine, but I'm just wanting
to make sure that I'm not doing anything that
could be wrong here.

Thanks in advance for any advice!

-- 
Jeff "Shippy" Shipman     E-Mail: shippy at nmt.edu
Computer Science Major    ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy




More information about the Python-list mailing list