[英]SSH Paramiko command is not changing the directory in remote server
I am trying to change the directory to /etc/init.d using SSH paramiko module and cd command. 我正在尝试使用SSH paramiko模块和cd命令将目录更改为/etc/init.d。 It is not changing the directory.
它不会更改目录。 It is at default directory 'root' after logged in to the server
登录到服务器后,它位于默认目录“ root”
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 输出:./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对象并在其上调用cd:
sftp = paramiko.SFTPClient.from_transport(ssh)
then 然后
sftp.cd(path)
to perform the cd remotely 远程执行cd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.