使用 Python 3 从 Windows 进行 SSH 和 SCP
我已经被困在这里好几天了。我想将文件从 Windows 复制到远程 Linux 服务器并在那里运行脚本。我有 ssh 和 scp 工具。我可以通过命令行调用linux服务器,但是当我通过python调用它时,它会被挂起。
pro=subprocess.Popen('ssh user@server')
pro.communicate()
有一个空白屏幕。之后我输入的任何内容都会出现在我的屏幕上。 我希望应该有密码提示,但没有。我想过使用像 paramiko、pexpect、pyssh 这样的库,但 Python 3 都不支持它们,
非常感谢任何帮助。
I've Been stuck here for days. I want to copy a file from my windows to a remote linux server and run the script there. I've tool for ssh and scp. from which I can call the linux server through command line but when I call it through python it gets hanged.
pro=subprocess.Popen('ssh user@server')
pro.communicate()
there is a blank screen. whatever I type then after appear to my screen.
I was hoping there should be a password prompt but there isn't any. I thought of using library like paramiko, pexpect, pyssh but none of them are supported in Python 3
Any help is highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://docs.fabfile.org/en/1.0.1/index.html
我不确定它是否可以通过 2to3 转换
,但使用起来相当简单:
env.host 来自命令行,twisted couch 是另一种选择,但尚未移植到 py3k
http://docs.fabfile.org/en/1.0.1/index.html
I'm not sure it can be converted by 2to3
but it's rather simple to use:
env.host comes from command line, twisted couch is another alternative but it's not yet ported to py3k
还有一个这样的问题。使用网猫。 “人数控”。 在 python 中使用 os.system() 在客户端和服务器端生成它。
来自 netcat 手册页:
这对于 Intranet 和 Internet 上的本地或远程计算机(如果了解的话)非常有用相关问题(原始问题没有指定“远程”的含义)。一些示例是:
“Netcat - TCP/IP 瑞士军刀 - SANS”
http://www .g-loaded.eu/2006/11/06/netcat-a- Couple-of-useful-examples/;请注意,此示例包括通过 netcat 进行的完整自动备份:“Netcat 对于创建分区映像并将其即时发送到远程计算机非常有用”
http://www.stearns.org/doc/nc-intro.v0.9.html ;使远程日志记录变得简单的示例。
至于评论“但这不是Python”:当有非常好的基础实用程序已经移植到所有操作系统并且除了底层基础操作系统之外没有其他依赖项时,不要重新发明轮子。
There was another question like this. Use netcat. 'man nc'. Use os.system() in python to spawn it on both client side and server side.
From the netcat manual page:
This works great for both local or remote machines on an intranet and also internet if aware of the related issues (original question did not specify the meaning of 'remote'). Some examples are:
"Netcat - The TCP/IP Swiss Army Knife - SANS"
http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/ ; Note this example includes complete automated backup via netcat: "Netcat is extremely useful for creating a partition image and sending it to a remote machine on-the-fly"
http://www.stearns.org/doc/nc-intro.v0.9.html ; An example for making dirt simple remote logging.
As for the comment "but that isn't python": Don't reinvent the wheel when there are very good foundational utilities which have been ported to all O/Ss and have no other dependencies other than the underlying base O/S.