使用子进程发送密码 [英] Use subprocess to send a password

查看:32
本文介绍了使用子进程发送密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 python 子进程模块登录到一个安全的 ftp 站点,然后抓取一个文件.但是,我一直在尝试在请求时发送密码.到目前为止,我有以下代码:

I'm attempting to use the python subprocess module to log in to a secure ftp site and then grab a file. However I keep getting hung up on just trying to send the password when it is requested. I so far have the following code:

from subprocess import Popen, PIPE

proc = Popen(['sftp','user@server', 'stop'], stdin=PIPE)
proc.communicate('password')

这仍然在密码提示处停止.如果我手动输入密码,它会转到 ftp 站点,然后在命令行上输入密码.我见过有人建议使用 pexpect 但长话短说我需要一个标准的库解决方案.无论如何有子进程和/或任何其他 stdlib 吗?我在上面忘记了什么?

This still stops at the password prompt. If I enter the password manually it then goes to the ftp site and then enters the password on the command line. I've seen people suggest using pexpect but long story short I need a standard library solution. Is there anyway with subprocess and/or any other stdlib? What am I forgetting above?

推荐答案

也许你应该使用 期待-like 图书馆吗?

Perhaps you should use an expect-like library instead?

例如 Pexpect (示例).还有其他类似的 Python 库.

For instance Pexpect (example). There are other, similar python libraries as well.

这篇关于使用子进程发送密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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