11

I am trying to make a very basic FTP client in python, and within the first few lines of code I have already run into a problem

My Code:

from ftplib import FTP
ftp = FTP('ftp.mysite.com')

With this code, and with countless different urls used, I will always get the same error:

gaierror: [Errno 11004] getaddrinfo failed
bs7280
  • 1,074
  • 3
  • 18
  • 32

2 Answers2

24

I found myself here with this error trying to connect using the full path rather than just the hostname. Make sure you split that out and use cwd(path) after login().

For example:

ftp = FTP('ftp.ncdc.noaa.gov')
ftp.login()
ftp.cwd('pub/data/noaa/2013')

instead of:

# Doesn't work!!
ftp = FTP('ftp.ncdc.noaa.gov/pub/data/noaa')
ftp.login()
ftp.cwd('2013')

Kind of obvious in hindsight, but hopefully I help you notice your simple mistake!

Alan Hensley
  • 731
  • 6
  • 9
5

Actually, this means that your computer can't resolve the domain name that you gave it. A detailed error description is available here. Try to use a well-known working FTP to test (e.g. ftp.microsoft.com). Then try to open the FTP you're trying to access with some FTP client.

Jan B.
  • 6,030
  • 5
  • 32
  • 53
cleg
  • 4,862
  • 5
  • 35
  • 52
  • Thank you! I was sure that I had tested well working domain names before but apparently not. – bs7280 Nov 23 '12 at 21:13
  • This is good advice, but the Microsoft ftp URL is outdated. This stackoverflow Q&A has a alternatives: https://stackoverflow.com/questions/7968703/is-there-a-public-ftp-server-to-test-upload-and-download – David Jan 01 '19 at 21:14