如果我运行command='ps'
或'ls'
且类似,则一切正常。但是,当我想从远程主机下载日志到winscp然后是一个问题时,没有错误但没有任何反应。
import sys
import time
import socket
import paramiko
import os
import telnetlib
import time
import subprocess
import os
hostname = 'localhost'
port = 22
command=('log -c')
pliczek='pliczek.txt'
client = paramiko.SSHClient()
def connection(hostname, port):
try:
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sock = socket.socket()
sock.connect((hostname, port))
t = paramiko.Transport(sock)
t.connect()
t.auth_none('root')
client._transport = t
except:
print ('Error')
def commands(command):
plik= open(pliczek, 'w+')
chan = client.get_transport().open_session()
stdin, stdout, stderr = client.exec_command(command)
stdin = client.exec_command(command)
output = stdout.readlines()
stdin.close()
lista=''.join(output)
print(lista)
plik.write(lista)
plik.close()
print lista
def close_sesion():
client.close()
print 'closed'