Help implementing an idea

Discussion in 'Python' started by Nicholas.Vaidyanathan@asu.edu, Jun 17, 2005.

  1. Guest

    Well, I'm a total python n00b, but I was playing around with exception handling
    yesterday, and was stricken by how incredibly easy it is to use the op system
    to create nice scripts... I did the following:

    import sys
    lines = sys.stdin.readlines()
    lines.sort()
    for stuff in lines:
    print stuff ,

    just to copy stuff from one file to another, and was quite impressed with the
    results. Now, I was thinking today, I'd really like to create a program that
    can go to a specific directory and upload all the files in the directory to a
    specific url for backup purposes, and I have the feeling that the python
    implementation would be ruthlessly small and efficient, like the
    above....anyone who could point me in the right direction as to how to actually
    do it?
     
    , Jun 17, 2005
    #1
    1. Advertising

  2. Guest

    , Jun 17, 2005
    #2
    1. Advertising

  3. rh0dium Guest

    Try this..


    #!/usr/bin/env python
    # Upload a file to a FTP server

    from sys import argv, exit
    from ftplib import FTP

    if len(argv) != 6:
    print 'Incorrect number of parameters'
    print 'USAGE: upload.py <server> <username> <password> <local
    file>
    <remote file>'
    exit(0)

    server = argv[1]
    username = argv[2]
    password = argv[3]
    upfile = argv[5]
    downfile = argv[4]

    try:
    print 'Connecting to %s' % server
    ftp = FTP(server)
    ftp.login(username, password)
    print 'Connection to %s opened' % server
    #send file in binary mode to server (STOR command sets remote
    filename)
    ftp.storbinary('STOR %s' % upfile, open(downfile,'r'))
    ftp.quit()
    print 'File %s uploaded' % upfile
    except Exception, err:
    print 'Error uploading file. Error: %s' % err
     
    rh0dium, Jun 17, 2005
    #3
  4. Tim Roberts Guest

    wrote:
    >
    >Well, I'm a total python n00b, but I was playing around with exception handling
    >yesterday, and was stricken by how incredibly easy it is to use the op system
    >to create nice scripts... I did the following:
    >
    >import sys
    >lines = sys.stdin.readlines()
    >lines.sort()
    >for stuff in lines:
    > print stuff ,


    Or sys.stdout.writelines( lines ).

    >just to copy stuff from one file to another, and was quite impressed with the
    >results. Now, I was thinking today, I'd really like to create a program that
    >can go to a specific directory and upload all the files in the directory to a
    >specific url for backup purposes, and I have the feeling that the python
    >implementation would be ruthlessly small and efficient, like the
    >above....anyone who could point me in the right direction as to how to actually
    >do it?


    How do you want to do the upload? FTP? That's easy. Check ftplib.py.
    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Jun 19, 2005
    #4
  5. gene tani Guest

    gene tani, Jun 19, 2005
    #5
  6. Fuzzyman Guest

    wrote:
    [snip..]
    > results. Now, I was thinking today, I'd really like to create a program that
    > can go to a specific directory and upload all the files in the directory to a
    > specific url for backup purposes, and I have the feeling that the python
    > implementation would be ruthlessly small and efficient, like the
    > above....anyone who could point me in the right direction as to how to actually
    > do it?


    Upload to a URL *sounds* like you want to do the upload by http rather
    than ftp.

    In this case you can do it with a Python CGI on the server and a script
    on the client that communicates with the CGI.

    When voidspace is back up you can find a pair of scripts that do just
    that :

    http://www.voidspace.org.uk/python/cgi.shtml#upload

    Hint - filelist = [os.path.join(directory, entry) for entry in
    os.listdir(directory)]

    Regards,

    Fuzzy
    http://www.voidspace.org.uk/python
     
    Fuzzyman, Jun 19, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Riccardo Fregonese

    Need help implementing a proj on SPARTAN3

    Riccardo Fregonese, Dec 2, 2004, in forum: VHDL
    Replies:
    2
    Views:
    717
    Thomas Gebauer
    Jan 3, 2005
  2. Andrew Pressel

    Re: Thoughts on implementing this idea

    Andrew Pressel, Jul 30, 2006, in forum: Perl
    Replies:
    0
    Views:
    1,837
    Andrew Pressel
    Jul 30, 2006
  3. Replies:
    10
    Views:
    1,244
    Big K
    Feb 2, 2005
  4. Dr Mephesto

    App idea, Any idea on implementation?

    Dr Mephesto, Feb 4, 2008, in forum: Python
    Replies:
    3
    Views:
    720
    Dennis Lee Bieber
    Feb 5, 2008
  5. Replies:
    0
    Views:
    635
Loading...

Share This Page