0

ここで、リモートサーバーでコマンドを実行して、コマンドごとにその出力を取得しようとしていますが、別の接続が必要ですが、別の接続またはセッションを作成すると、応答が非常に遅くなります。

私が実行しようとしているコードは、しかし、それは動作していません:

import pysftp
import paramiko

commandlist = ("ls", "uname -a","whoami")
ans = []
sftp = pysftp.Connection("localhost",username="root",password="123456",port=22)
for i in commandlist:
    try: 
        out = sftp.execute(i)
        ans.append(out)
    except (paramiko.ssh_exception.AuthenticationException,paramiko.ssh_exception.SSHException), e:
        ans.append(e)
return ans

作業コードは次のとおりです。

import pysftp
import paramiko
commandlist = ("ls", "uname -a")
ans = []
for i in commandlist:
    try: 
        sftp = pysftp.Connection("localhost",username="root",password="123456",port=222)
        out = sftp.execute(i)[0]
        ans.append(out)
    except (paramiko.ssh_exception.AuthenticationException,paramiko.ssh_exception.SSHException), e:
        ans.append(e)
return ans

ここで、実行するすべてのコマンドの接続を作成しています。私を助けてください。paramiko や fabric などの他のライブラリでこれを実行できるかどうか、またその方法を教えてください。

ありがとう。

4

0 に答える 0