我已经能够在远程服务器上使用 ssh 和发出命令。现在我想从远程服务器中获取 scp 文件,但这似乎是不可能的。我对 python 和 Paramiko 完全陌生。该错误是在我该死的 Windows 本地目录中被拒绝的权限。这些文件应该来自 Mac。我可以使用任何其他非常非常简单的示例将文件从远程 Linux 计算机发送到本地 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)
最佳答案
从远程主机获取文件到本地目录:
......
localpath='C:\\Users\\handsonexpert\\Documents\\file3.txt'
remotepath='/Users/ihussain/testdir/file3.txt'
......
sftp.get(remotepath, localpath)
关于python - 使用 paramiko 的 scp 不起作用 - ssh 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14954406/