1

I am trying to connect to SFTP server but it returns error:

[Errno 11001] getaddrinfo failed

I am using Python 3.7.3 and Paramiko version is 2.6.0

import paramiko

host_name = "sftp://81.149.151.143"
user_name = "******"
password = "******"

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=host_name, port=220, username=user_name, password=password)

ftp_client=ssh_client.open_sftp()
ftp_client.put('***/issue_1.docx', '/issue_1.docx') 
ftp_client.close()

This is the full error:

Traceback (most recent call last):
  File "/sftp/paramiko_bot.py", line 10, in <module>
    ssh_client.connect(hostname=host_name, port=22, username=user_name, password=password)
  File "\Local\Programs\Python\Python37\lib\site-packages\paramiko\client.py", line 340, in connect
    to_try = list(self._families_and_addresses(hostname, port))
  File "\Local\Programs\Python\Python37\lib\site-packages\paramiko\client.py", line 204, in _families_and_addresses
    hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM
  File "\AppData\Local\Programs\Python\Python37\lib\socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

1

The hostname parameter of SSHClient.connect should contain a hostname only (or in your case an IP address) – not any kind of URL.

ssh_client.connect(hostname="81.149.151.143", port=220, username=..., password=...)

Obligatory warning: Do not use AutoAddPolicy this way – You are losing a protection against MITM attacks by doing so. For a correct solution, see Paramiko "Unknown Server"

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992