Python:执行scp,stdin以使密码不起作用 [英] Python: Execute scp, stdin for password not working

查看:365
本文介绍了Python:执行scp,stdin以使密码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下

from subprocess import Popen, PIPE
Popen(["scp", "-B","user@url:file", "."], stdin=PIPE, shell=False).communicate(input="password")

但是我仍然收到密码promt,并且没有发送密码. 我知道我可以在密钥上使用scp,但这不是我所需要的.

But I still get the password promt, and no password is sent. I know I can use scp with keys, but this is not what I need.

有帮助吗?

推荐答案

scp 直接与终端进行交互,而不是从 STDIN 中读取,您无法通过通过管道输入密码,对于scp来说是安全的问题,对于sftp,ssh来说也是一样.

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 .

这篇关于Python:执行scp,stdin以使密码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆