Update: see comments for my solution.
My python code uses urllib2 to access an FTP server through a proxy with a user and password. I use both urllib2.ProxyHandler and urllib2.ProxyBasicAuthHandler to implement this, following urllib2 examples :
1 import urllib2 2 proxy_host = 'host.proxy.org:3128'
The code stops at line 7.
error messages:
conn = urllib2.urlopen(remote_fn) File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 391, in open response = self._open(req, data) File "/usr/lib/python2.6/urllib2.py", line 409, in _open '_open', req) File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 1344, in ftp_open fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout) File "/usr/lib/python2.6/urllib2.py", line 1365, in connect_ftp fw = ftpwrapper(user, passwd, host, port, dirs, timeout) File "/usr/lib/python2.6/urllib.py", line 856, in __init__ self.init() File "/usr/lib/python2.6/urllib.py", line 862, in init self.ftp.connect(self.host, self.port, self.timeout) File "/usr/lib/python2.6/ftplib.py", line 134, in connect self.welcome = self.getresp() File "/usr/lib/python2.6/ftplib.py", line 209, in getresp resp = self.getmultiline() File "/usr/lib/python2.6/ftplib.py", line 195, in getmultiline line = self.getline() File "/usr/lib/python2.6/ftplib.py", line 185, in getline if not line: raise EOFError urllib2.URLError: <urlopen error ftp error: >
I tested the proxy server by specifying the env variable ftp_proxy and accessing the ftp file using
wget --proxy-user=proxy_user --proxy-password=proxy_passwd ftp:
and he successfully downloaded the file from the ftp server.
How can I improve my code to access an ftp site using authentication proxies?