I'm using the code below to ssh into the 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. On the main ftp server
I'm trying to connect to, I get this error:
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?
To fix your 2nd error, you can tell Paramiko to auto-add new servers:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
Take a look at the docs .
For your second problem, you need to add the following line after 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.