Search code examples
pythonftpftplib

Accessing FTP server with Python fails with "getaddrinfo" error


I am trying to access the open DLP Test FTP server as a practice. I keep getting a getaddrinfo error but I am unsure of where I'm going wrong. I am using Python 2 on a Windows 10, and have already checked that I am not behind a proxy.

Code:

from ftplib import FTP
ftp = FTP('ftp://ftp.dlptest.com/')
...

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\ftplib.py", line 120, in __init__
    self.connect(host)
  File "C:\Python27\lib\ftplib.py", line 135, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout)
  File "C:\Python27\lib\socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed

Any help is appreciated!


Solution

  • Use

    ftp = FTP('ftp.dlptest.com')
    

    instead.

    The first argument of FTP constructor is host – a hostname or an IP address – not a URL.