Paramiko: calling “cd” command with exec_command does nothing

左心房为你撑大大i 提交于 2019-12-08 13:26:34

It looks like you are implementing some kind of interactive program that allows executing a sequence of commands on the server.

The SSHClient.exec_command executes each command in a separate "exec" channel. The individual commands run in their own environment. So if you execute cd command, it has no effect at all on subsequent commands. They will again start in user's home directory.

If you want to implement an interactive shell session, use SSHClient.invoke_shell.
For an example, see how to interact with Paramiko's interactive shell session?

See also Execute multiple commands in Paramiko so that commands are affected by their predecessors.

Paramiko SSH_Client opens a new session and executes the command in that session and once command execution gets completed, the session channel is closed.

Executing 'cd' command would have been done in the first session and later on, for the next command the session would start again from home directory.

If you want to hold the session, use invoke_shell for an interactive session.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!