使用Paramiko在Python中ssh到ftp服务器
我正在使用下面的代码ssh到使用Paramiko在Python中ssh到ftp服务器,python,ssh,ftp,paramiko,Python,Ssh,Ftp,Paramiko,我正在使用下面的代码ssh到ftp服务器中: 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 但是,我使用多个服务器,所以我经常替换server参数。在我试图连接到的主ftp服务器上,出现以下
ftp服务器中
:
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
但是,我使用多个服务器,所以我经常替换server
参数。在我试图连接到的主ftp服务器上,出现以下错误:
socket.error: [Errno 60] Operation timed out
paramiko.ssh_exception.S SHException:
Server 'ftp.server.org' not found in known_hosts
但每当我尝试使用其他服务器时,通常会出现以下错误:
socket.error: [Errno 60] Operation timed out
paramiko.ssh_exception.S SHException:
Server 'ftp.server.org' not found in known_hosts
有人知道解决这两个问题中的一个或两个的可能解决方案吗?对于第二个问题,您需要在ssh=paramiko.SSHClient()之后添加以下行:
这将允许paramiko自动接受未知密钥(并应允许您通过SSH连接到其他服务器)要修复第二个错误,您可以告诉paramiko自动添加新服务器:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
看看。哎呀。。。对不起,我很忙,昨天没有回复您(不管怎样,下面的答案都是正确的)您的ftp服务器是否运行SSH服务器?请检查它们是否正在运行,并且端口22未被防火墙阻止。