Python 脚本 - Windows 上的 SCP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/729130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python script - SCP on windows
提问by nosklo
How is it possible to do secure copy using python (windows native install - ActivePython). Unfortunately pexpect module is for unix only and we don't want cygwin locally. I wrote a script that based on pscp.exe win tool - but always stops at first execution becuse of fingerprint host id. and haven't found option to switch this off. the remote hosts are running ssh-server on cygwin (win 2003 servers).
如何使用 python 进行安全复制(windows native install - ActivePython)。不幸的是, pexpect 模块仅适用于 unix,我们不想在本地使用 cygwin。我写了一个基于 pscp.exe win 工具的脚本 - 但总是在第一次执行时停止,因为指纹主机 ID。并且还没有找到关闭它的选项。远程主机在 cygwin(win 2003 服务器)上运行 ssh-server。
Thanks
谢谢
回答by Nicholas Riley
paramikois pretty slick. See this questionfor some more details.
回答by Benson
I strongly recommend that you use keys rather than passwords. If you use ssh keys properly, you do not need to use expect, as the scp command won't ask for any user input. If you have command line ssh installed, you can make a key like this:
我强烈建议您使用密钥而不是密码。如果正确使用 ssh 密钥,则不需要使用 expect,因为 scp 命令不会要求任何用户输入。如果你安装了命令行 ssh,你可以像这样创建一个密钥:
ssh-keygen -t dsa
Then simply follow the instructions provided, and save the key to the default location. If you put a passphrase on it, you'll need to use some sort of ssh agent, either the command line ssh-agent or pagent on windows. You can also create an ssh key with the putty suite's puttygen.
然后只需按照提供的说明进行操作,并将密钥保存到默认位置。如果您在上面设置了密码,则需要使用某种 ssh 代理,命令行 ssh-agent 或 Windows 上的 pagent。您还可以使用 putty 套件的 puttygen 创建 ssh 密钥。
To set up the key for authentication, simply put a copy of id_dsa.pub on the host you want to scp to in the file ~/.ssh/authorized_keys.
要设置用于身份验证的密钥,只需将 id_dsa.pub 的副本放在要 scp 到的主机上的 ~/.ssh/authorized_keys 文件中。
回答by vartec
回答by nosklo
Twisted Conchsupports ssh and sftp.
Twisted Conch支持 ssh 和 sftp。
回答by unwind
How do you expect to provide the authentication data? The easiest way is to create a key, and make sure it is in the server's list of accepted hosts. That way scp will authenticate using the private/public key pair automatically, and "just work".
您希望如何提供身份验证数据?最简单的方法是创建一个密钥,并确保它在服务器的接受主机列表中。这样 scp 将自动使用私钥/公钥对进行身份验证,并且“正常工作”。
Thisis a handy tutorial on how to go about creating and uploading the key. Of course this assumes you have the necessary admin access to the server.
这是一个关于如何创建和上传密钥的方便教程。当然,这假设您对服务器具有必要的管理员访问权限。