简体   繁体   English

SSH Paramiko命令未更改远程服务器中的目录

[英]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.

相关问题 使用 Paramiko 更改 SFTP 服务器上的目录 - Changing directory on SFTP server with Paramiko 如何使用SCP或SSH将完整目录递归复制到Python(paramiko)中的远程服务器? - How to copy a complete directory recursively to a remote server in Python (paramiko) using SCP or SSH? 将远程(Paramiko)ssh 命令的输出评估为成功/失败布尔值 - Evaluating a remote (Paramiko) ssh command's output into a success/failure boolean 将使用 Paramiko SSH 执行的远程命令的输入链接到本地​​ Python 控制台 - Linking input of remote command executed with Paramiko SSH to local Python console 命令可在SSH上使用,但不能与Paramiko一起使用 - Command working on SSH but not with Paramiko 使用 Paramiko 从远程服务器执行命令到另一个远程服务器 - Executing command from remote server into another remote server using Paramiko 使用Python Paramiko在后台运行远程SSH服务器的过程 - Running process of remote SSH server in the background using Python Paramiko Paramiko-远程命令执行 - Paramiko - Remote command execution 在 Python Paramiko 中的 SSH 服务器上的辅助 shell/命令中执行(子)命令 - Execute (sub)commands in secondary shell/command on SSH server in Python Paramiko 读取在 SSH 服务器上执行的命令的 output 作为字符串,而不是字节 - Read output of a command executed on SSH server with Paramiko as string, not as bytes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM