0

I have to read the zip,rar and 7z file present in the server and extract there itself for further processing. I am using paramiko and python. I have a sftp file but I am not able to pass it through Patool library.

remote_file = sftp_client.open(output[i],'rb')
sftp = ssh_client.open_sftp()
file = ftp.file(output[i], "r", -1)
lines = file.readlines()
print(lines)
patoolib.extract_archive(output[i], outdir=inputPath)

Here output[i] is remote server zip file path.

jmd_dk
  • 12,125
  • 9
  • 63
  • 94
RajAt SiNha
  • 97
  • 1
  • 1
  • 8
  • Can you try to explain what do you think your code does? -- What is even `ftp.file`? + You never use the `sftp` variable. + I do not think that `patoolib.extract_archive` can work with remote paths. Logging in with Paramiko won't make other Python modules magically be able to access remote files. – Martin Prikryl Nov 11 '19 at 14:09
  • I am actually trying to unzip the zipped files present in the server using patoolib.extract_archive if possible, if not how can I decode sftp file to get data present inside those zipped files? – RajAt SiNha Nov 11 '19 at 14:40
  • *"unzip the zipped files present in the server"* can mean lot of different things. For instance, do you want to unzip the files to local machine or to remote machine? If to local, why don't you simply download the zip file and unzip it locally? – Martin Prikryl Nov 11 '19 at 14:41
  • I want to unzip in remote machine which is a windows machine and no 3rd party apps is to be installed on that system. Is something like this possible? – RajAt SiNha Nov 11 '19 at 14:44

1 Answers1

0

You cannot unzip files on remote server using SFTP protocol. That's not possible.

You cannot use client-side libraries to unzip a non-local file either. You would have to download the archive (to a temporary local file or at least to a memory), extract it and upload the extracted files. What can be very slow.

Best you can do (if you have a shell access) is to execute (using SSH) any available command on the remote server to do the extraction.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992