Problem getting shutil.copy() to transfer files to my Web site - ?!

Randy Burgess rburgess1 at hvc.rr.com
Sun Dec 22 12:44:40 EST 2002


Hi,

 I tooled up a simple CGI script w/Python to transfer files from my desktop
to my Web site (I'm actually going to use this with a project to help others
transfer .DOC and .TXT files to my site w/out an FTP client.)
   It worked fine testing it on localhost (I run Xitami), but bombs out on
my Web hosting service's unix box. Python gives me an error message like
"Can't copy C:\test\test.txt to /home/www/usable-thought/cgi-bin: (2, 'No
such file or directory') .
   Not sure what could be wrong - code snippet below. If anyone has ideas
I'd be grateful. I'm a novice at this but find Python very useful. Thanks! -
Randy Burgess - rburgess at usable-thought.com

if form.has_key('FILE'):
    from shutil import copy
    okay_filetypes = ["doc", "xls", "txt", "htm", "html"]
    import os
    upload_path = os.getcwd() # returns something like
/home/www/usable-thought/cgi-bin
    import string
    if string.lower(filepath.value[-3:]) in okay_filetypes:
        try:
            copy(filepath.value, upload_path)
            htmlPrintLine("Your document was saved under its own name to " +
upload_path)
        except (IOError, os.error), why:
            print "Can't copy %s to %s: %s" % (filepath.value, upload_path,
str(why)) # debugging
            htmlPrintLine("<b>Error:</b> Invalid filename or path - try
again!")

    else:
        types = list_to_string(okay_filetypes)
        htmlPrintLine("<b>Error:</b> Document not uploaded - we only accept
" + types + ".")






More information about the Python-list mailing list