I am trying to change the directory to /etc/init.d using SSH paramiko module and cd command. It is not changing the directory. It is at default directory 'root' after logged in to the server
def StopAll(path,IP,ROOT,PASSWD):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('%s'%IP, username='%s'%ROOT,password='%s'%PASSWD)
stdin, stdout, stderr = ssh.exec_command("cd /etc/init.d")
stdin, stdout, stderr = ssh.exec_command("pwd")
print stdout.read().strip()
Output : ./Installation.py conf/Input.conf
/root
Please tell me where is the problem in code .
you need to grab the sftp object and call cd on that:
sftp = paramiko.SFTPClient.from_transport(ssh)
then
sftp.cd(path)
to perform the cd remotely
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.