Open file on remote linux server

Martien Verbruggen martien.verbruggen at invalid.see.sig
Fri Oct 2 09:00:04 CEST 2009

On Wed, 23 Sep 2009 23:41:35 +0200,
	Diez B. Roggisch <deets at> 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')
    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')
    # To read
    fh = ftp.file('/tmp/foo.test', 'r')
    for l in fh:
        print l,

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

Martien Verbruggen           | You can't have everything, where would
first.last at | you put it?

More information about the Python-list mailing list