Open file on remote linux server

T

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)

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)
 
S

Sean DiZazzo

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)

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
 
D

Diez B. Roggisch

The said:
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
 
N

Neil Hodgson

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
 
M

Martien Verbruggen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top