remote unzip

morecowbell hoteljorba at gmail.com
Sat Nov 1 01:39:39 EDT 2008


greetings,


i got a bunch of zip files on a remote server and need to get to one
of the files, an xml file, in each of the archives. fairly simple to
do locally with zipfile but i don't seem to be able to combine that
local code with the paramiko sftp client. a rather simplified code
snippet to illustrate:

import os
import paramiko
import StringIO
import zipfile

remote_file = 'remote.zip'
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh",
"known_hosts")))
ssh.connect('www.xxx.com', username='root', password='it_aint')
sftp = ssh.open_sftp()
dirlist = sftp.listdir('.')
zipfile = sftp.file('remote.zip', 'r')
unzip = ZipFile(zfile)
for f in unzip.namelist():
    if f.endswith('.xml'):
        output.write(unzip.read(unzip))
        xmlfiles.append(output.getvalue())

sftp.close()
ssh.close()

any help is greatly appreacited



More information about the Python-list mailing list