--- ftplib.py Thu Feb 15 14:54:36 2007 +++ ftplib_new.py Thu Feb 15 14:56:23 2007 @@ -321,6 +321,12 @@ host, port = self.makepasv() af, socktype, proto, canon, sa = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0] conn = socket.socket(af, socktype, proto) + # Bind to the same local address used for the control connection + # on any available port. + myaddr = self.sock.getsockname()[0] + conn.bind((myaddr,0)) + if self.debugging: + print "*bind* " + myaddr + ":" + repr(conn.getsockname()[1]) conn.connect(sa) if rest is not None: self.sendcmd("REST %s" % rest)