1

I'm using Paramiko to ssh into a telecom switch that doesn't support using the exec_command(). So i'm using invoke_shell() and send() instead.

What i'm trying to do is ssh, exec a cmd, then sftp the file. Here's a snippet.

<code>
chan.send(cmd4)
time.sleep(5)
if chan.recv_ready():
    result = chan.recv(1024)
    while chan.recv_ready():
        result += chan.recv(1024)
print(result)
exit_status = chan.recv_exit_status()
if exit_status == 0:
    try:
        sftp = ssh.open_sftp()
        sftp.get(remotePath,path) 
        sftp.close()
    except:
        print "sftp error"
else:
    print("exit status not 0")
chan.close()
</code>

The problem is the command can take anyway from 10mins to 2 hours depending on the switch. So how would i wait until the command is finished before i try to sftp?

Franco
  • 57
  • 1
  • 6
  • i dont think the switch has the luxury of not supporting `exec_command` as under the hood it just opens a shell and sends the command and gives you back stdout stderr and stdin pipes ... (see : https://github.com/paramiko/paramiko/blob/master/paramiko/client.py#L459) – Joran Beasley Aug 28 '18 at 17:10
  • 1
    I don't think so. It still uses the exec_command. When i try i get this similar error. [link](https://stackoverflow.com/questions/32697981/paramiko-issues-channel-closed-when-executing-a-command) following this solution. – Franco Aug 28 '18 at 18:16
  • whoops you are right ... sorry i feel dumb... anyway keep polling result until you get a string that indicates that the command has finished (this is probably just until you re-encounter the system prompt... of coarse if it never encounters the prompt you may hang indefinately... ) – Joran Beasley Aug 28 '18 at 20:21

0 Answers0