我有一个使用Paramiko模块通过sftp上传zip文件的脚本。我试图解压缩这个zip文件,但是它没有起作用。我没有收到任何反馈,告诉我它不起作用。
import paramiko, re
spaceNeeded = 11534336
localpath = 'C:\\Users\\username\\Downloads\\10_Recommended.zip'
remotepath = '/tmp/10_Recommended.zip'
sudopass = "password"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('host', username='username', password='password')
stdin, stdout, stderr =ssh.exec_command("df -k /tmp | grep /tmp | tr -s ' ' ',' | cut -d ',' -f4")
actualSpace = ''.join(stdout.readlines())
if actualSpace > spaceNeeded:
transport = paramiko.Transport(('host',22))
transport.connect(username="username", password="password")
sftp = paramiko.SFTPClient.from_transport(transport)
print "Starting upload"
sftp.put(localpath, remotepath)
stdin, stdout, stderr =ssh.exec_command("ls /tmp | grep 10_Recommended.zip")
zipfile = ''.join(stdout.readlines())
print "Unzipping file"
stdin, stdout, stderr = ssh.exec_command("unzip /tmp/10_Recommended.zip")