Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 303c179

Browse files
committed
add bind(0,''); better way of guessing our fully qualified hostname
1 parent 8d2033f commit 303c179

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/ftplib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def sendport(self, port):
211211
def makeport(self):
212212
global nextport
213213
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
214+
sock.bind(('', 0))
214215
sock.listen(1)
215216
host, port = sock.getsockname()
216217
resp = self.sendport(port)
@@ -234,7 +235,13 @@ def login(self, user = '', passwd = '', acct = ''):
234235
# Make sure it is fully qualified
235236
if not '.' in thishost:
236237
thisaddr = socket.gethostbyname(thishost)
237-
thishost = socket.gethostbyaddr(thisaddr)[0]
238+
firstname, names, unused = \
239+
socket.gethostbyaddr(thisaddr)
240+
names.insert(0, firstname)
241+
for name in names:
242+
if '.' in name:
243+
thishost = name
244+
break
238245
try:
239246
if os.environ.has_key('LOGNAME'):
240247
realuser = os.environ['LOGNAME']

0 commit comments

Comments
 (0)