python - 使用 Python 3 从 Windows 进行 SSH 和 SCP

标签 python ssh python-3.x scp

我已经被困在这里好几天了。我想将文件从我的 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/

相关文章:

Python:如何从依赖模块的另一个文件中正确导入函数

linux - Github 权限被拒绝 (publickey) SSH key 位于错误的目录中?

git - 具有 ssh 访问 bitbucket : Permission denied (publickey). fatal error 的 Jenkins git 插件:无法从远程存储库读取

java - 拒绝 HostKey : when deploying JAR with gradle ssh plugin

python - Physik Instrumente 的 PI Python 库

python - Apache Airflow 中调度程序间隔和启动时间的工作不正确

尝试使用主键添加重复条目时,Python 忽略 MySQL IntegrityError

Python Pandas : converting several boolean columns into a (possibly repeated) column made up of the boolean column names

python - 如何创建没有索引错误的 folium.choropleth map ?

Python编程使用API​​错误