ftplib

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • William Manley
    New Member
    • Mar 2007
    • 56

    #1

    ftplib

    I want to upload a file to my server, I understand I should use the storlines() method, but I don't understand what cmd should be.

    and fp would be the file object I want to upload, correct?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by William Manley
    I want to upload a file to my server, I understand I should use the storlines() method, but I don't understand what cmd should be.

    and fp would be the file object I want to upload, correct?
    Here are Basic FTP Commands to get you going.

    Comment

    • William Manley
      New Member
      • Mar 2007
      • 56

      #3
      According to that page the command I would need would be 'put', I tried that but got this:

      Traceback (most recent call last):
      File "C:/Documents and Settings/William/Desktop/ftp.py", line 6, in <module>
      ftp.storlines(' put', open('C:/config/quotes/website/index.html', 'r'))
      File "C:\Python25\li b\ftplib.py", line 426, in storlines
      conn = self.transfercm d(cmd)
      File "C:\Python25\li b\ftplib.py", line 345, in transfercmd
      return self.ntransferc md(cmd, rest)[0]
      File "C:\Python25\li b\ftplib.py", line 327, in ntransfercmd
      resp = self.sendcmd(cm d)
      File "C:\Python25\li b\ftplib.py", line 241, in sendcmd
      return self.getresp()
      File "C:\Python25\li b\ftplib.py", line 216, in getresp
      raise error_perm, resp
      error_perm: 500 Unknown command

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        typical put eg:
        Code:
        from ftplib import FTP
        import sys, getpass, os.path
        host, username, localfile, remotepath = sys.argv[1:]
        password = getpass.getpass("Enter password for %s on %s: " % \
                (username, host))
        f = FTP(host)
        f.login(username, password)
        
        f.cwd(remotepath)
        fd = open(localfile, 'rb')
        f.storbinary('STOR %s' % os.path.basename(localfile), fd)
        fd.close()
        
        f.quit()

        Comment

        • William Manley
          New Member
          • Mar 2007
          • 56

          #5
          Thank you.

          Comment

          Working...