Python: Execute scp, stdin for password not working

僤鯓⒐⒋嵵緔 提交于 2019-12-07 12:40:36

scp interacts with the terminal directly, rather than reading from STDIN, You can't pass the password via a pipe, it security matter for scp and it's the same for sftp, ssh.

you can try it in you terminal like this (and it will not work):

echo "password" | scp me@localhost:test .

As others have said, scp (and ssh) read the password directly from the console instead of stdin, so using subprocess to send the password will not work. You can use pexpect instead - see the docs and numerous examples for how to do this.

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