It seems that ftplib couldn't support active-mode when simulating client-ip using socket with monkey patch
<p>I want to write a script to simulate multi_source_ip to access FTP server under active_mode. of course, I has bind the simulated ip address on my NIC.
  Due to ftplib couldn't provide a parameter to set ip, so I have to use socket with monkey patch to achieve it, it do work under passive_mode, but doesn't work in active_mode, what else way I use to do it under active_mode ?
  the code as follows</p>

<pre><code>&gt;&gt;&gt; from ftplib import FTP 
&gt;&gt;&gt; import socket

&gt;&gt;&gt; true_socket = socket.socket
&gt;&gt;&gt; def bound_socket(*a, **k):
...     sock = true_socket(*a, **k)
...     sock.bind(('10.0.8.100', 0))
...     return sock
... 
&gt;&gt;&gt; socket.socket = bound_socket
&gt;&gt;&gt; f = FTP()
&gt;&gt;&gt; f.connect('10.0.8.202')
'220 welcome to RS 10.70.0.202'
&gt;&gt;&gt; f.login("anonymous","ff@")
'230 Login successful.' 
&gt;&gt;&gt; f.cwd('pub')
'250 Directory successfully changed.'
&gt;&gt;&gt; f.set_pasv(False)
&gt;&gt;&gt; f.dir()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/lib/python2.6/ftplib.py", line 513, in dir
    self.retrlines(cmd, func)
  File "/usr/lib/python2.6/ftplib.py", line 421, in retrlines
    conn = self.transfercmd(cmd)
  File "/usr/lib/python2.6/ftplib.py", line 360, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib/python2.6/ftplib.py", line 341, in ntransfercmd
    sock = self.makeport()
  File "/usr/lib/python2.6/ftplib.py", line 289, in makeport
    raise socket.error, msg
socket.error: [Errno 22] Invalid argument
&gt;&gt;&gt; 
</code></pre>
