I have a script to upload a zip file through sftp with the Paramiko module. I'm trying to unzip the zip file, but it's not working. I don't get any feedback that says it's not working.
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")
Your ssh connection may be closed before unzipping is done. I had a similar problem and added stdout.read() after exec_command to force the connection to be open until unzip is done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With