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

Cliff Wells clifford.wells at attbi.com
Sun Dec 22 14:06:51 EST 2002


On Sun, 2002-12-22 at 09:44, Randy Burgess wrote:
> 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') .

I was very confused by this thread until it dawned on me what you are
trying to do:  you are trying to have a cgi script on a remote server
pull a file from the user's pc.  I'm willing to be corrected on this,
but this doesn't seem possible.  Further, if it is, please let me know
which browsers it works with so I can avoid them like the plague. 

Anyway, the simplest solution to what you are trying to do is this: 
have the clients ftp the files to a directory on the server and have a
cgi pick them up.  Even Windows comes with an ftp client.  If they truly
don't have one, put a link to somewhere they can download one (or write
one in python).

The bottom line is the user will have to send the file to you, you can't
go out and get it.




>    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 + ".")
-- 
Cliff Wells <clifford.wells at attbi.com>





More information about the Python-list mailing list