Open file on remote linux server

Discussion in 'Python' started by The Bear, Sep 23, 2009.

  1. The Bear

    The Bear Guest

    Hi I'm looking to do something like this

    f = f.openfileobj(remotefileloc, localfilelikeobj)

    my remote files are on a solaris box that i can access using ssh (could
    prehap request othe protocols if necessary)

    anyone got any ideas?

    many thanks

    Charlie

    (ps. tried this on the python-forum but didn't seem to go on so apologies if
    i'm cross posting)
    --
    View this message in context: http://www.nabble.com/Open-file-on-remote-linux-server-tp25531253p25531253.html
    Sent from the Python - python-list mailing list archive at Nabble.com.
    The Bear, Sep 23, 2009
    #1
    1. Advertising

  2. The Bear

    Sean DiZazzo Guest

    On Sep 23, 12:04 pm, The Bear <> wrote:
    > Hi I'm looking to do something like this
    >
    > f = f.openfileobj(remotefileloc, localfilelikeobj)
    >
    > my remote files are on a solaris box that i can access using ssh (could
    > prehap request othe protocols if necessary)
    >
    > anyone got any ideas?
    >
    > many thanks
    >
    > Charlie
    >
    > (ps. tried this on the python-forum but didn't seem to go on so apologies if
    > i'm cross posting)
    > --
    > View this message in context:http://www.nabble.com/Open-file-on-remote-linux-server-tp25531253p255...
    > Sent from the Python - python-list mailing list archive at Nabble.com.


    I don't know of any Python library that will give you that kind of
    access to a remote file over ssh. It sounds like a fun project
    though!

    If nothing else, you can install the ssh filesystem for Fuse, and just
    mount the remote filesystem as if it was local.

    ~Sean
    Sean DiZazzo, Sep 23, 2009
    #2
    1. Advertising

  3. The Bear schrieb:
    > Hi I'm looking to do something like this
    >
    > f = f.openfileobj(remotefileloc, localfilelikeobj)
    >
    > my remote files are on a solaris box that i can access using ssh (could
    > prehap request othe protocols if necessary)
    >
    > anyone got any ideas?


    try paramiko. Or just use subprocess to scp and open the file locally.


    Diez
    Diez B. Roggisch, Sep 23, 2009
    #3
  4. The Bear

    Neil Hodgson Guest

    The Bear:
    > Hi I'm looking to do something like this
    >
    > f = f.openfileobj(remotefileloc, localfilelikeobj)
    >
    > my remote files are on a solaris box that i can access using ssh (could
    > prehap request othe protocols if necessary)


    You could look into GIO which is a virtual file system API used in
    GTK+. I was a bit put off by it (necessarily) exposing the asynchronous
    nature of remote file operations. Its fun to write a small amount of
    asynchronous file I/O code but ensuring that all of your code handles
    all the potential problems with remote connections is tedious.

    Base library:
    http://library.gnome.org/devel/gio/stable/

    Python bindings:
    http://library.gnome.org/devel/pygobject/stable/

    Before committing to this, you should double check that these are the
    currently supported APIs. There was an earlier API GnomeVFS that has
    been deprecated for several years now and I don't follow this area closely.

    Neil
    Neil Hodgson, Sep 24, 2009
    #4
  5. On Wed, 23 Sep 2009 23:41:35 +0200,
    Diez B. Roggisch <> wrote:
    > The Bear schrieb:
    >> Hi I'm looking to do something like this
    >>
    >> f = f.openfileobj(remotefileloc, localfilelikeobj)
    >>
    >> my remote files are on a solaris box that i can access using ssh (could
    >> prehap request othe protocols if necessary)
    >>
    >> anyone got any ideas?

    >
    > try paramiko. Or just use subprocess to scp and open the file locally.



    import paramiko

    ssh = paramiko.SSHClient()
    ssh.load_system_host_keys(os.environ['HOME'] + '/.ssh/known_hosts')
    ssh.connect('localhost')
    try:
    ftp = ssh.open_sftp()
    # To write
    fh = ftp.file('/tmp/foo.test', 'w')
    fh.write('This is a test string\nAnd this is another one')
    fh.close()
    # To read
    fh = ftp.file('/tmp/foo.test', 'r')
    for l in fh:
    print l,
    fh.close()
    finally:
    ssh.close()

    You may need to add some password handling in there (for me my
    environment takes care of that).

    Martien
    --
    |
    Martien Verbruggen | You can't have everything, where would
    | you put it?
    |
    Martien Verbruggen, Oct 2, 2009
    #5
    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. Kevin Spencer
    Replies:
    3
    Views:
    2,988
    Kevin Spencer
    Aug 15, 2003
  2. jake
    Replies:
    0
    Views:
    336
  3. =?Utf-8?B?cmV5Y29u?=

    can't access file on a remote file server

    =?Utf-8?B?cmV5Y29u?=, Jun 3, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,061
    agrnidhi
    May 24, 2007
  4. Schüle Daniel

    File::open and File.open

    Schüle Daniel, Oct 23, 2006, in forum: Ruby
    Replies:
    4
    Views:
    178
    Rick DeNatale
    Oct 24, 2006
  5. Dayton Jones

    Remote.pm (File::Remote) problem

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

Share This Page