FTP upload issue

afrobeard afrobeard at gmail.com
Thu May 15 17:25:29 EDT 2008


First of all, it would be better to use:-

ftp.storlines("STOR " + remoteFileName, open(localFileName, "rb"))

rather than:-

ftp.storlines("STOR" + filename, file(filename))

Since the Python Documentation has this to say for open(): [Although ]

When opening a file, it's preferable to use open() instead of invoking
this constructor directly. file is more suited to type testing (for
example, writing "isinstance(f, file)").

Secondly Referring to another mail thread :
http://mail.python.org/pipermail/tutor/2006-February/045347.html
Quoting Kent :

fname should be just a bare name, e.g. 'mac.info2.txt'. You have to
ftp.cwd()
to the correct directory yourself. If it does not exists, create a tmp
directory. You're currently passing /tmp/mac.info2.txt to the ftp.

This should hopefully solve your problem.

P.S. I personally used to use ftputil[Really easy to use] and now I
use twisted. These libraries abstract a lot of stuff out for you.

On May 16, 1:25 am, davidj411 <davidj... at gmail.com> wrote:
> I am having difficulty uploading a text file using Python 2.5 on MAC
> OSX.
>
> SCRIPT
>
> filename='/tmp/mac.info2.txt'
> fh=open(filename,'w')
> fh.write('yes, i have a mac but don't hold that against me - just
> example data')
> fh.close()
>
> from ftplib import FTP
> 'host, username, and password are string variables that have already
> been defined.
> ftp = FTP(host)
> ftp.login(username,password)
> 'so far, logged in, all is well , error is on next line.
>
> ftp.storlines("STOR" + filename, file(filename))
> ftp.quit()
>
> What am i doing wrong?  the file DOES exist, the path is correct, and
> the file  was closed after being written. file(filename) should open
> it again for the upload?
>
> http://www.python.org/doc/lib/ftp-objects.htmlsays that the command
> should be an appropriate "STOR" command: "STOR filename". file is an
> open file object which is read...
>
> ERROR
>   File "mac.inventory.py", line 44, in <module>
>     ftp.storlines("STOR " + filename, file(filename))
>   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/ftplib.py", line 437, in storlines
>     conn = self.transfercmd(cmd)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/ftplib.py", line 356, in transfercmd
>     return self.ntransfercmd(cmd, rest)[0]
>   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/ftplib.py", line 327, in ntransfercmd
>     resp = self.sendcmd(cmd)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/ftplib.py", line 241, in sendcmd
>     return self.getresp()
>   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/ftplib.py", line 216, in getresp
>     raise error_perm, resp
> ftplib.error_perm: 550 /tmp/mac.info2.txt: The system cannot find the
> path specified.




More information about the Python-list mailing list