Basic Python FTP Question

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

    #1

    Basic Python FTP Question

    I have just discovered how to do ftp with python, and have a question
    about using macdef.

    I can connect to the ftp site, using the .netrc file:

    machine my.ftpsite.com
    login myuserid
    password mypass
    macdef dload
    cd maindir
    get myfile


    and the python command:

    cmdline = "ftp my.ftpsite.com" % ()
    os.system(cmdli ne)


    but, once I connect, I would like to be able to enter more
    commands to do whatever kind of ftp I want.

    But the way it seems to work is that you can have a macdef init
    which will do the same thing every time you connect.

    If the macdef is named anything else, such as 'dload' as in the example,
    above, there doesn't seem to be any way to enter a python command to
    execute it.

    I would like to have in the .netrc:

    macdef def1
    commands

    macdef def2
    commands

    macdef def3
    commands

    etc.

    and then somehow be able to run macdef def1 or macdef def2 etc.,
    depending on what I am doing within the python script.

    Or if it's not a matter of having the macdefs in the .netrc file, then I
    would like to know how to set up the proper ftp commands in python.

    I hope this makes sense. I have the feeling I am missing some obvious
    thing.

  • Ravi Teja

    #2
    Re: Basic Python FTP Question

    Have you seen Python's ftplib?

    Source code: Lib/ftplib.py This module defines the class FTP and a few related items. The FTP class implements the client side of the FTP protocol. You can use this to write Python programs that pe...


    Comment

    • Bob Piton

      #3
      Re: Basic Python FTP Question

      On Wed, 08 Mar 2006 00:09:34 -0800, Ravi Teja wrote:
      [color=blue]
      > Have you seen Python's ftplib?
      > http://effbot.org/librarybook/ftplib.htm
      > http://docs.python.org/lib/module-ftplib.html[/color]

      No I hadn't. Thanks for the references; it looks like that method will do
      anything I need to do with ftp.

      Comment

      Working...