summaryrefslogtreecommitdiffstats
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-08-04 04:39:30 (GMT)
committerGuido van Rossum <guido@python.org>1995-08-04 04:39:30 (GMT)
commit221ec0b97abab7c7444355370ddf4819d808e59c (patch)
tree024c00e7a2226e882b69aa7c308198c8d803fee7 /Lib/ftplib.py
parent28e99fe96fe6f51ab7bd39a531c0bd5deff1e440 (diff)
downloadcpython-221ec0b97abab7c7444355370ddf4819d808e59c.zip
cpython-221ec0b97abab7c7444355370ddf4819d808e59c.tar.gz
cpython-221ec0b97abab7c7444355370ddf4819d808e59c.tar.bz2
new sendport() interface; add test() program call
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r--Lib/ftplib.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index f27ab06..8801dfd 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -198,10 +198,8 @@ class FTP:
self.voidresp()
# Send a PORT command with the current host and the given port number
- def sendport(self, port):
- hostname = socket.gethostname()
- hostaddr = socket.gethostbyname(hostname)
- hbytes = string.splitfields(hostaddr, '.')
+ def sendport(self, host, port):
+ hbytes = string.splitfields(host, '.')
pbytes = [`port/256`, `port%256`]
bytes = hbytes + pbytes
cmd = 'PORT ' + string.joinfields(bytes, ',')
@@ -213,8 +211,9 @@ class FTP:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('', 0))
sock.listen(1)
- host, port = sock.getsockname()
- resp = self.sendport(port)
+ dummyhost, port = sock.getsockname() # Get proper port
+ host, dummyport = self.sock.getsockname() # Get proper host
+ resp = self.sendport(host, port)
return sock
# Send a port command and a transfer command, accept the connection
@@ -439,3 +438,7 @@ def test():
ftp.retrbinary('RETR ' + file, \
sys.stdout.write, 1024)
ftp.quit()
+
+
+if __name__ == '__main__':
+ test()