Linux 使用 paramiko 的 scp 不起作用 - ssh 工作正常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14954406/
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
scp using paramiko doesnt work - ssh works fine
提问by Doublespeed
I have been able to use ssh and issue command in the remote server. Now I want to scp files from the remote server but that just seems like its impossible. I'm totally new to python and Paramiko. The error is permission denied in my local directory of darn windows. The files are supposed to come from the Mac. Any other really really simple example I can use to scp files from a remote Linux machine to my local Windows machine?
我已经能够在远程服务器中使用 ssh 并发出命令。现在我想从远程服务器 scp 文件,但这似乎是不可能的。我对 python 和 Paramiko 完全陌生。错误是在我的该死的 Windows 本地目录中被拒绝权限。这些文件应该来自Mac。我可以使用任何其他非常简单的示例将文件从远程 Linux 机器 scp 到我的本地 Windows 机器吗?
import paramiko
hostname = '192.xx.1.xx'
password = 'pop123'
username = "husbad2"
port = 22
mypath='C:\Users\handsonexpert\Documents'
remotepath='/Users/ihussain/testdir/file3.txt'
t = paramiko.Transport((hostname, 22))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(mypath, remotepath)
采纳答案by Ali-Akber Saifee
To retrieve files from a remote host into a local directory:
要将文件从远程主机检索到本地目录:
......
localpath='C:\Users\handsonexpert\Documents\file3.txt'
remotepath='/Users/ihussain/testdir/file3.txt'
......
sftp.get(remotepath, localpath)
回答by danodonovan
You're not using scp
here, but SFTP
(SFTPClient
).
您不是scp
在这里使用,而是SFTP
( SFTPClient
)。
If you're set on using scp
, maybe take a look at this paramiko scpclient, there is an example of how to use it here.
如果你正在使用一组scp
,也许看看这个的paramiko SCP客户端,有一个如何使用它的一个例子在这里。
Aside, out of general security interests and programming style, don'thard code your password and user credentials, and especially neverpublish them in a public forum like SO. We don't need them and you don't need to post them.
此外,出于一般的安全利益和编程风格,不要硬编码您的密码和用户凭据,尤其不要在像 SO 这样的公共论坛上发布它们。我们不需要它们,您也不需要发布它们。