FTP Ignorance

I spent over an hour trying to run the sample code below. This comes from the sample code from ftputil (The best FTP library for Python by the way.)

# download some files from the login directory
import ftputil
host = ftputil.FTPHost('ftp://ftp.kernel.org/')
names = host.listdir(host.curdir)
for name in names:
    if host.path.isfile(name):
        host.download(name, name, 'b')        # remote, local, binary mode

And I just kept getting this error!

raise FTPOSError(ftp_error)
FTPOSError: (11001, 'getaddrinfo failed')
Debugging info: ftputil 2.1.1, Python 2.4.2 (win32)

Anyway the simple mistake ended up being that I needed to use ftp.kernel.org/ and not ftp://ftp.kernel.org/. So that’s the answer if you’re ever stuck, omit the ftp:// prefix.

2 Responses to “FTP Ignorance”

  1. Actually while I was reading your code example I thought to myself: “FTPHost taking an URL argument seems like bad API design, since the protocol is obviously fixed and the ftp:// prefix therefore redundant and a potential source of errors.” Seems like the ftputil developers thought the same.

  2. I agree, Sebastian. The ftputil developers did do the right thing. I think I was either tired or hungry or something this afternoon.