Re: write to remote ile

Discussion in 'Python' started by Martin P. Hellwig, Mar 8, 2010.

  1. On 03/08/10 02:10, monkeys paw wrote:
    > I can xfer a file from a remote server using:
    >
    > import urllib2 as u
    > x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
    >
    > for line in x:
    > print line
    >
    >
    > How can i write a file to the remote server?
    >
    > I tried:
    >
    > x = u.url.open('http://joemoney.net/somefile.txt', 'w')
    >
    > but that does not work


    How do you normally (i.e. without python) put files on a remote server?

    --
    mph
    Martin P. Hellwig, Mar 8, 2010
    #1
    1. Advertising

  2. On 03/08/10 02:51, monkeys paw wrote:
    > On 3/7/2010 9:20 PM, Martin P. Hellwig wrote:
    >> On 03/08/10 02:10, monkeys paw wrote:
    >>> I can xfer a file from a remote server using:
    >>>
    >>> import urllib2 as u
    >>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
    >>>
    >>> for line in x:
    >>> print line
    >>>
    >>>
    >>> How can i write a file to the remote server?
    >>>
    >>> I tried:
    >>>
    >>> x = u.url.open('http://joemoney.net/somefile.txt', 'w')
    >>>
    >>> but that does not work

    >>
    >> How do you normally (i.e. without python) put files on a remote server?
    >>

    > Using FTP, i'm really having a brain cramp here, but i'm new to python


    We all been there, in some for or other ;-), anyway you might want to
    have a look at this:
    http://docs.python.org/library/ftplib.html

    --
    mph
    Martin P. Hellwig, Mar 8, 2010
    #2
    1. Advertising

  3. Martin P. Hellwig

    MRAB Guest

    monkeys paw wrote:
    > On 3/7/2010 9:53 PM, Martin P. Hellwig wrote:
    >> On 03/08/10 02:51, monkeys paw wrote:
    >>> On 3/7/2010 9:20 PM, Martin P. Hellwig wrote:
    >>>> On 03/08/10 02:10, monkeys paw wrote:
    >>>>> I can xfer a file from a remote server using:
    >>>>>
    >>>>> import urllib2 as u
    >>>>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
    >>>>>
    >>>>> for line in x:
    >>>>> print line
    >>>>>
    >>>>>
    >>>>> How can i write a file to the remote server?
    >>>>>
    >>>>> I tried:
    >>>>>
    >>>>> x = u.url.open('http://joemoney.net/somefile.txt', 'w')
    >>>>>
    >>>>> but that does not work
    >>>>
    >>>> How do you normally (i.e. without python) put files on a remote server?
    >>>>
    >>> Using FTP, i'm really having a brain cramp here, but i'm new to python

    >>
    >> We all been there, in some for or other ;-), anyway you might want to
    >> have a look at this:
    >> http://docs.python.org/library/ftplib.html
    >>

    >
    > Tried this, the storlines doesn't work, everything else OK
    >
    > from ftplib import FTP
    > ftp = FTP('joemoney.net')
    > ftp.login('secret','pw')
    > ftp.retrlines('LIST') # list directory contents
    > ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error>
    >

    The documentation says:

    FTP.storlines(cmd, file, callback=None)

    where 'cmd' is the FTP command, 'STOR sf.xml' ('sf.xl' is the path of
    the file on the server) and 'file' is the open (local) source file.
    MRAB, Mar 8, 2010
    #3
  4. On Mon, 08 Mar 2010 15:30:39 -0500, monkeys paw <>
    declaimed the following in gmane.comp.python.general:

    > ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error>


    Error 1: You didn't supply the destination file name on the STOR
    command

    Error 2: You didn't supply an open file object from which to retrieve
    the lines to be transferred

    myfile = open(local_file_name, "rt")
    ftp.storlines("STOR sf.xml", myfile)
    myfile.close()

    All of which you could have found by reading the standard library
    documentation supplied with Python.

    >From the help system:

    -=-=-=-=-=-=-
    storbinary( command, file[, blocksize])

    Store a file in binary transfer mode. command should be an appropriate
    "STOR" command: "STOR filename". file is an open file object which is
    read until EOF using its read() method in blocks of size blocksize to
    provide the data to be stored. The blocksize argument defaults to 8192.
    Changed in version 2.1: default for blocksize added.

    storlines( command, file)

    Store a file in ASCII transfer mode. command should be an appropriate
    "STOR" command (see storbinary()). Lines are read until EOF from the
    open file object file using its readline() method to provide the data to
    be stored.
    -=-=-=-=-=-=-

    --
    Wulfraed Dennis Lee Bieber KD6MOG
    HTTP://wlfraed.home.netcom.com/
    Dennis Lee Bieber, Mar 9, 2010
    #4
    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. davidj411
    Replies:
    7
    Views:
    3,237
    Tim Golden
    Oct 8, 2009
  2. Tim Chandler
    Replies:
    0
    Views:
    202
    Tim Chandler
    Oct 7, 2003
  3. Jeff Wood
    Replies:
    7
    Views:
    185
    Jeff Wood
    Oct 18, 2005
  4. Markus Arike
    Replies:
    2
    Views:
    93
    Markus Arike
    Aug 19, 2008
  5. Dayton Jones

    Remote.pm (File::Remote) problem

    Dayton Jones, Mar 1, 2006, in forum: Perl Misc
    Replies:
    9
    Views:
    175
    Dayton Jones
    Mar 3, 2006
Loading...

Share This Page