我已经被困在这里好几天了。我想将文件从我的 Windows 复制到远程 Linux 服务器并在那里运行脚本。我有 ssh 和 scp 的工具。我可以从中通过命令行调用 linux 服务器,但是当我通过 python 调用它时,它会被挂起。
pro=subprocess.Popen('ssh user@server')
pro.communicate()
有一个空白屏幕。无论我输入什么,然后都会出现在我的屏幕上。 我希望应该有密码提示,但没有。我想过使用像 paramiko、pexpect、pyssh 这样的库,但 Python 3 都不支持它们
非常感谢任何帮助。
最佳答案
http://docs.fabfile.org/en/1.0.1/index.html
我不确定它是否可以通过2to3转换
但它使用起来相当简单:
from fabric.api import run, env
from fabric.context_managers import hide
from fabric.colors import green
with hide('status', 'running', 'output'):
print('Apache ' + env.host + ': ' + green(run('wget -q -O /dev/null http://localhost/ && echo OK')))
env.host 来自命令行,twisted couch 是另一种选择,但尚未移植到 py3k
关于python - 使用 Python 3 从 Windows 进行 SSH 和 SCP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6097278/