Paramiko and Pseudo-tty Allocation

前端 未结 4 1894
暖寄归人
暖寄归人 2020-11-28 11:54

I\'m trying to use Paramiko to connect to a remote host and execute a number of text file substitutions.

i, o, e = client.exec_command(\"perl -p -i -e \'s/         


        
4条回答
  •  一向
    一向 (楼主)
    2020-11-28 12:38

    The following code works for me:

    #!/usr/bin/env python
    import paramiko
    
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect('localhost',username='root',password='secret')
    chan = ssh.get_transport().open_session()
    chan.get_pty()
    chan.exec_command('tty')
    print(chan.recv(1024))
    

    This was just assembled from looking at a few examples online... not sure if its the "right" way.

提交回复
热议问题