summaryrefslogtreecommitdiffstats
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-01-04 21:36:31 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-01-04 21:36:31 (GMT)
commit7b4b28469b0c7b588f371d19fb4da90d63787b09 (patch)
tree380b7c39ae8d343eef209f5c73eb7b1af029c7f0 /Lib/ftplib.py
parent9fe67ceebf697f8a49854badf704ceee122968cf (diff)
downloadcpython-7b4b28469b0c7b588f371d19fb4da90d63787b09.zip
cpython-7b4b28469b0c7b588f371d19fb4da90d63787b09.tar.gz
cpython-7b4b28469b0c7b588f371d19fb4da90d63787b09.tar.bz2
allow a SSLContext to be given to ftplib.FTP_TLS
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r--Lib/ftplib.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 0a69b7a..e1c3d99 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -641,9 +641,21 @@ else:
ssl_version = ssl.PROTOCOL_SSLv23
def __init__(self, host='', user='', passwd='', acct='', keyfile=None,
- certfile=None, timeout=_GLOBAL_DEFAULT_TIMEOUT):
+ certfile=None, context=None,
+ timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None):
+ if context is not None and keyfile is not None:
+ raise ValueError("context and keyfile arguments are mutually "
+ "exclusive")
+ if context is not None and certfile is not None:
+ raise ValueError("context and certfile arguments are mutually "
+ "exclusive")
self.keyfile = keyfile
self.certfile = certfile
+ if context is None:
+ context = ssl._create_stdlib_context(self.ssl_version,
+ certfile=certfile,
+ keyfile=keyfile)
+ self.context = context
self._prot_p = False
FTP.__init__(self, host, user, passwd, acct, timeout)
@@ -660,8 +672,8 @@ else:
resp = self.voidcmd('AUTH TLS')
else:
resp = self.voidcmd('AUTH SSL')
- self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile,
- ssl_version=self.ssl_version)
+ self.sock = self.context.wrap_socket(self.sock,
+ server_hostname=self.host)
self.file = self.sock.makefile(mode='rb')
return resp
@@ -692,8 +704,8 @@ else:
def ntransfercmd(self, cmd, rest=None):
conn, size = FTP.ntransfercmd(self, cmd, rest)
if self._prot_p:
- conn = ssl.wrap_socket(conn, self.keyfile, self.certfile,
- ssl_version=self.ssl_version)
+ conn = self.context.wrap_socket(conn,
+ server_hostname=self.host)
return conn, size
def retrbinary(self, cmd, callback, blocksize=8192, rest=None):