Open file on remote linux server
Martien Verbruggen
martien.verbruggen at invalid.see.sig
Fri Oct 2 03:00:04 EDT 2009
On Wed, 23 Sep 2009 23:41:35 +0200,
Diez B. Roggisch <deets at 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 at heliotrope.com.au | you put it?
|
More information about the Python-list
mailing list