On an sFTP server I have gzipped files, each containing one zip file, which in turn do contain multiple files. What I want to retrieve is a complete list of files contained in the zipfiles. This is what I have put together so far by googling, but it doesn't seem to do anything. The gziplist
works though.
Any ideas on what I'm doing wrong, or better yet - a better approach?
ssh_stdin, ssh_stdout, ssh_stderr = conn.exec_command(f'ls /{client}/Data/ | grep ".ZIP.gz"\n', get_pty=True)
gziplist = []
for i in ssh_stdout.read().decode("utf-8").split('\r\n'):
gziplist.append(i)
ssh_stdin, ssh_stdout, ssh_stderr = conn.exec_command(f'zless /{client}/Data/{i}\n', get_pty=True)
gzcontent = ''
for line in ssh_stdout.readlines():
gzcontent = gzcontent+line
gzfile = gzip.open(gzcontent)
content = gzfile.read()
contentbytes = zipfile.ZipFile(io.BytesIO(content))
print(contentbytes.namelist())