ftplib question: how to upload files?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • python@sarcastic-horse.com

    #1

    ftplib question: how to upload files?

    Hi:

    I want to write a procedure to automatically upload some files for me, but
    I'm getting stuck. Before I write my own gruesome put() function, I
    wanted to check if there is an easier way.

    Here's what I can do so far:[color=blue][color=green][color=darkred]
    >>>import ftplib
    >>>conn = ftplib.FTP('ftp .example.com')
    >>>conn.login(u ser='userid', passwd='passwd' )
    >>>conn.cwd('/var/www/html/incoming')[/color][/color][/color]

    What do I do to send files?

    I have three files I want to upload, but I'm not sure what to do. I hoped
    to find a ftplib.put() method, but it looks like ftplib is a low-level
    interface.

    All help is welcome.


  • Patrick Useldinger

    #2
    Re: ftplib question: how to upload files?

    On Thu, 11 Sep 2003 14:35:32 -0400 (EDT), python@sarcasti c-horse.com
    wrote:

    [color=blue]
    >What do I do to send files?[/color]

    I use this:

    f=file(fileName ,'rb')
    conn.storbinary ('STOR '+os.path.basen ame(fileName),f )

    -PU

    Comment

    • Anthony McDonald

      #3
      Re: ftplib question: how to upload files?

      <python@sarcast ic-horse.com> wrote in message
      news:mailman.10 63305377.21943. python-list@python.org ...[color=blue]
      > Hi:
      >
      > I want to write a procedure to automatically upload some files for me, but
      > I'm getting stuck. Before I write my own gruesome put() function, I
      > wanted to check if there is an easier way.
      >
      > Here's what I can do so far:[color=green][color=darkred]
      > >>>import ftplib
      > >>>conn = ftplib.FTP('ftp .example.com')
      > >>>conn.login(u ser='userid', passwd='passwd' )
      > >>>conn.cwd('/var/www/html/incoming')[/color][/color]
      >
      > What do I do to send files?
      >
      > I have three files I want to upload, but I'm not sure what to do. I hoped
      > to find a ftplib.put() method, but it looks like ftplib is a low-level
      > interface.
      >
      > All help is welcome.
      >
      >[/color]
      The methods your searching for are storlines (for ascii) or storbinary (for
      non ascii).

      You can simplyfy the process slightly with your own wrapper to those 2
      methods to guess the file mode and call the correct method with the STOR
      command created for you. An example is below.

      def upload(conn, fname):
      (head, tail) = os.path.split(f name)
      command = "STOR " + tail
      fd = open(fname, 'rb')
      temp = fd.read(2048)
      fd.seek(0, 0)
      if temp.find('\0') != -1:
      conn.storbinary (command, fd)
      else:
      conn.storlines( command, fd)
      fd.close()

      Anthony McDonald


      Comment

      • Steve Holden

        #4
        Re: ftplib question: how to upload files?

        <python@sarcast ic-horse.com> wrote in message
        news:mailman.10 63305377.21943. python-list@python.org ...[color=blue]
        > Hi:
        >
        > I want to write a procedure to automatically upload some files for me, but
        > I'm getting stuck. Before I write my own gruesome put() function, I
        > wanted to check if there is an easier way.
        >
        > Here's what I can do so far:[color=green][color=darkred]
        > >>>import ftplib
        > >>>conn = ftplib.FTP('ftp .example.com')
        > >>>conn.login(u ser='userid', passwd='passwd' )
        > >>>conn.cwd('/var/www/html/incoming')[/color][/color]
        >
        > What do I do to send files?
        >
        > I have three files I want to upload, but I'm not sure what to do. I hoped
        > to find a ftplib.put() method, but it looks like ftplib is a low-level
        > interface.
        >
        > All help is welcome.
        >[/color]

        See if the code in



        will help. It's supposed to make FTP easier.

        regards
        --
        Steve Holden http://www.holdenweb.com/
        Python Web Programming http://pydish.holdenweb.com/pwp/



        Comment

        Working...