如何使用paramiko python从sftp文件解码Zip文件 [英] How to decode Zip file from sftp file using paramiko python

查看:86
本文介绍了如何使用paramiko python从sftp文件解码Zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须阅读服务器中存在的 zip、rar 和 7z 文件,然后将其解压缩以进行进一步处理.我正在使用 paramiko 和 python.我有一个 sftp 文件,但我无法通过 Patool 库传递它.

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)

这里output[i]是远程服务器的zip文件路径.

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

推荐答案

您无法使用 SFTP 协议在远程服务器上解压缩文件.这是不可能的.

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.

你能做的最好的事情(如果你有 shell 访问权限)是在远程服务器上执行(使用 SSH)任何可用的命令来进行提取.

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.

这篇关于如何使用paramiko python从sftp文件解码Zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆