gpt4 book ai didi

Python2.7 : ssh. exec_command 没有执行任何命令

转载 作者:太空宇宙 更新时间:2023-11-04 05:28:11 26 4
gpt4 key购买 nike

<分区>

我正在使用 paramiko 创建到远程主机的 SSH channel 。但是,当我尝试使用 ssh_object.exec_command 执行任何命令时,该命令似乎并未执行。

此函数创建我的 ssh 处理程序:

def ssh_connect(ip,user,pwd):
'''
This function will make an ssh connection to the ip using the credentials passed and return the handler
Args:
ip: IP Address of the box into which ssh has to be done
user: User name of the box to which ssh has to be done
pass: password of the box to which ssh has to be done
Returns:
An ssh handler
'''
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=user, password=pwd)
return ssh

这就是我使用处理程序的地方:

ssh_obj = ssh_connect(ip, username, password)
folder = "/var/xyz/images/" + build_number
command = "mkdir " + folder
ssh_stdin, ssh_stdout, ssh_stderr = ssh_obj.exec_command(command)

当我转到远程机器时,文件夹尚未创建。同样,我也尝试读取 ls 命令的输出。当我执行 ssh_stdout.read() 时没有响应。

我哪里错了?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com