I'm creating an SSH Channel
to a remote host using paramiko
. However, when I try to execute any command using the ssh_object.exec_command
, the command doesn't seem to get executed.
This function creates my ssh
handler:
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
And this is where I'm using the handler:
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)
When I go to the remote machine, the folder has not got created. Similarly, I tried reading the output of an ls
command as well. No response arrives when I do ssh_stdout.read()
.
Where am I going wrong?