My code belove gives me the error: socket.gaierror: [Errno 11001] getaddrinfo failed
when calling the method ftp.connect().
My question is: why can I connect to google.com but when connecting to an ftp server it gives me error? And how I can connect to the ftp server from behind http proxy?
import ftplib
import urllib.request
# ftp settings
ftpusername = 'abc'
ftppassword = 'xyz'
ftp_host = 'host'
ftp_port = 1234
proxy_url = 'http://username:password@host:port'
proxy_support = urllib.request.ProxyHandler({'http': proxy_url})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
#url works ok
f = urllib.request.urlopen('http://www.google.com/')
print(f.read(500))
# Connecting to ftp fails
with ftplib.FTP() as ftp:
ftp.connect(host=ftp_host, ftp_port=port)
ftp.login(user=ftpusername, passwd=ftppassword)
print(ftp.getwelcome())
print(ftp.nlst())
ftp.close()
ftp.quit()