Reputation: 1865
I'm looking to download a csv file from our FTP every evening. I'm getting an error when I attempt to run the script saying "socket.gaierror: [Errno 11001] getaddrinfo failed". Here's the code I'm using:
import ftplib
ftp = ftplib.FTP('http://192.168.0.00', 'username', 'password')
files = ftp.dir('/')
ftp.cwd("/")
filematch = '*.csv'
target_dir = '/path/to/csv/file'
import os
for filename in ftp.nlst(filematch):
target_file_name = os.path.join(target_dir,os.path.basename(filename))
with open(target_file_name,'wb') as fhandle:
ftp.retrbinary('RETR %s' %filename, fhandle.write)
Not sure what exactly is wrong with my code. Could it be something with the directory formatting, or the FTP format?
Thanks!
Upvotes: 0
Views: 3301
Reputation: 17159
The signature ftplib.FTP()
is
ftplib.FTP([host[, user[, passwd[, acct[, timeout]]]]])
So you need to provide a hostname as a first argument not an URL.
Make it
ftp = ftplib.FTP('192.168.0.00', 'username', 'password')
P.S. Is it really 192.168.0.00
with a 00
as the last octet?
Upvotes: 1