[英]Using Paramiko to ssh into ftp servers in Python
I'm using the code below to ssh into the ftp servers
: 我正在使用下面的代码ssh进入
ftp servers
:
ssh = paramiko.SSHClient()
ssh.connect(server, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("locate my_file.txt")
print ssh_stdout
However, I'm using multiple servers so I replace the server
argument a lot. 但是,我使用了多个服务器,因此我替换了很多
server
参数。 On the main ftp server
I'm trying to connect to, I get this error: 在我尝试连接的主
ftp server
上,出现以下错误:
socket.error: [Errno 60] Operation timed out
Whenever I try to use other servers though, I usually get this error: 每当我尝试使用其他服务器时,通常会出现此错误:
paramiko.ssh_exception.S SHException:
Server 'ftp.server.org' not found in known_hosts
Does anyone know of any possible solutions to solve either one or both of these problems? 有谁知道解决任何一个或两个问题的可能解决方案?
For your second problem, you need to add the following line after ssh = paramiko.SSHClient()
: 对于第二个问题,您需要在
ssh = paramiko.SSHClient()
之后添加以下行:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
This will allow paramiko to auto-accept unknown keys (and should allow you to SSH into those other servers) 这将允许paramiko自动接受未知密钥(并应允许您通过SSH进入其他服务器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.