I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)
Any ideas how to do it?
As per this source.
Depends on the proxy, but a common method is to ftp to the proxy, then use the username and password for the destination server.
E.g. for ftp.example.com:
In Python code:
Here is workaround using
requests
, tested with a squid proxy that does NOT support CONNECT tunneling:Patching the builtin socket library definitely won't be an option for everyone, but my solution was to patch
socket.create_connection()
to use an HTTP proxy when the hostname matches a whitelist:I also had to create a subclass of ftplib.FTP that ignores the
host
returned byPASV
andEPSV
FTP commands. Example usage:I had the same problem and needed to use the ftplib module (not to rewrite all my scripts with URLlib2).
I have managed to write a script that installs transparent HTTP tunneling on the socket layer (used by ftplib).
Now, I can do FTP over HTTP transparently !
You can get it there: http://code.activestate.com/recipes/577643-transparent-http-tunnel-for-python-sockets-to-be-u/
Standard module
ftplib
doesn't support proxies. It seems the only solution is to write your own customized version of theftplib
.You can use the ProxyHandler in
urllib2
.