Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Open file on remote linux server (http://www.velocityreviews.com/forums/t699242-open-file-on-remote-linux-server.html)

The Bear 09-23-2009 07:04 PM

Open file on remote linux server
 

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-r...p25531253.html
Sent from the Python - python-list mailing list archive at Nabble.com.


Sean DiZazzo 09-23-2009 07:41 PM

Re: Open file on remote linux server
 
On Sep 23, 12:04*pm, The Bear <c.poll...@bangor.ac.uk> 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-r...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

Diez B. Roggisch 09-23-2009 09:41 PM

Re: Open file on remote linux server
 
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

Neil Hodgson 09-24-2009 12:12 AM

Re: Open file on remote linux server
 
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

Martien Verbruggen 10-02-2009 07:00 AM

Re: Open file on remote linux server
 
On Wed, 23 Sep 2009 23:41:35 +0200,
Diez B. Roggisch <deets@nospam.web.de> 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
first.last@heliotrope.com.au | you put it?
|


All times are GMT. The time now is 03:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.