FTP upload issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davidj411

    FTP upload issue

    I am having difficulty uploading a text file using Python 2.5 on MAC
    OSX.

    SCRIPT

    filename='/tmp/mac.info2.txt'
    fh=open(filenam e,'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(usern ame,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.html says 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.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 437, in storlines
    conn = self.transfercm d(cmd)
    File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 356, in transfercmd
    return self.ntransferc md(cmd, rest)[0]
    File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 327, in ntransfercmd
    resp = self.sendcmd(cm d)
    File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 241, in sendcmd
    return self.getresp()
    File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 216, in getresp
    raise error_perm, resp
    ftplib.error_pe rm: 550 /tmp/mac.info2.txt: The system cannot find the
    path specified.


  • afrobeard

    #2
    Re: FTP upload issue

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

    ftp.storlines(" STOR " + remoteFileName, open(localFileN ame, "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 :

    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...@gmai l.comwrote:
    I am having difficulty uploading a text file using Python 2.5 on MAC
    OSX.
    >
    SCRIPT
    >
    filename='/tmp/mac.info2.txt'
    fh=open(filenam e,'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(usern ame,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.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 437, in storlines
        conn = self.transfercm d(cmd)
      File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 356, in transfercmd
        return self.ntransferc md(cmd, rest)[0]
      File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 327, in ntransfercmd
        resp = self.sendcmd(cm d)
      File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 241, in sendcmd
        return self.getresp()
      File "/System/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
    python2.5/ftplib.py", line 216, in getresp
        raise error_perm, resp
    ftplib.error_pe rm: 550 /tmp/mac.info2.txt: The system cannot find the
    path specified.

    Comment

    Working...