Issue #23881: urllib.ftpwrapper constructor now closes the socket if the FTP
connection failed.
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 2408cb8..9f972e3 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -871,7 +871,11 @@
         self.timeout = timeout
         self.refcount = 0
         self.keepalive = persistent
-        self.init()
+        try:
+            self.init()
+        except:
+            self.close()
+            raise
 
     def init(self):
         import ftplib