remote unzip
Stefan Behnel
stefan_ml at behnel.de
Sat Nov 1 06:35:18 EDT 2008
morecowbell wrote:
> 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()
I suppose this code doesn't work for you? What's the output you get?
"don't seem to be able" is not a very helpful problem description.
Stefan
More information about the Python-list
mailing list