您可以在以下网址找到大量的paramiko
API文档:http
://docs.paramiko.org/en/stable/index.html
import paramikonbytes = 4096hostname = 'hostname'port = 22username = 'username' password = 'password'command = 'ls'client = paramiko.Transport((hostname, port))client.connect(username=username, password=password)stdout_data = []stderr_data = []session = client.open_channel(kind='session')session.exec_command(command)while True: if session.recv_ready(): stdout_data.append(session.recv(nbytes)) if session.recv_stderr_ready(): stderr_data.append(session.recv_stderr(nbytes)) if session.exit_status_ready(): breakprint 'exit status: ', session.recv_exit_status()print ''.join(stdout_data)print ''.join(stderr_data)session.close()client.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)