Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
16ba98cc
Commit
16ba98cc
authored
Jun 27, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge heads
parents
dd6098b8
096dcb1e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
2 deletions
+47
-2
Doc/library/ftplib.rst
Doc/library/ftplib.rst
+8
-0
Doc/whatsnew/3.3.rst
Doc/whatsnew/3.3.rst
+11
-0
Lib/ftplib.py
Lib/ftplib.py
+8
-0
Lib/test/test_ftplib.py
Lib/test/test_ftplib.py
+20
-2
No files found.
Doc/library/ftplib.rst
View file @
16ba98cc
...
...
@@ -426,6 +426,14 @@ FTP_TLS Objects
Set up secure control connection by using TLS or SSL, depending on what specified in :meth:`ssl_version` attribute.
.. method:: FTP_TLS.ccc()
Revert control channel back to plaintex. This can be useful to take
advantage of firewalls that know how to handle NAT with non-secure FTP
without opening fixed ports.
.. versionadded:: 3.3
.. method:: FTP_TLS.prot_p()
Set up secure data connection.
...
...
Doc/whatsnew/3.3.rst
View file @
16ba98cc
...
...
@@ -192,6 +192,17 @@ The :mod:`ssl` module has new functions:
* :func:`~ssl.RAND_pseudo_bytes`: generate pseudo-random bytes.
ftplib
------
The :class:`~ftplib.FTP_TLS` class now provides a new
:func:`~ftplib.FTP_TLS.ccc` function to revert control channel back to
plaintex. This can be useful to take advantage of firewalls that know how to
handle NAT with non-secure FTP without opening fixed ports.
(Patch submitted by Giampaolo Rodolà in :issue:`12139`.)
Optimizations
=============
...
...
Lib/ftplib.py
View file @
16ba98cc
...
...
@@ -708,6 +708,14 @@ else:
self
.
file
=
self
.
sock
.
makefile
(
mode
=
'r'
,
encoding
=
self
.
encoding
)
return
resp
def
ccc
(
self
):
'''Switch back to a clear-text control connection.'''
if
not
isinstance
(
self
.
sock
,
ssl
.
SSLSocket
):
raise
ValueError
(
"not using TLS"
)
resp
=
self
.
voidcmd
(
'CCC'
)
self
.
sock
=
self
.
sock
.
unwrap
()
return
resp
def
prot_p
(
self
):
'''Set up secure data connection.'''
# PROT defines whether or not the data channel is to be protected.
...
...
Lib/test/test_ftplib.py
View file @
16ba98cc
...
...
@@ -303,11 +303,11 @@ if ssl is not None:
_ssl_closing
=
False
def
secure_connection
(
self
):
self
.
del_channel
()
socket
=
ssl
.
wrap_socket
(
self
.
socket
,
suppress_ragged_eofs
=
False
,
certfile
=
CERTFILE
,
server_side
=
True
,
do_handshake_on_connect
=
False
,
ssl_version
=
ssl
.
PROTOCOL_SSLv23
)
self
.
del_channel
()
self
.
set_socket
(
socket
)
self
.
_ssl_accepting
=
True
...
...
@@ -342,7 +342,10 @@ if ssl is not None:
# http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
pass
self
.
_ssl_closing
=
False
if
getattr
(
self
,
'_ccc'
,
False
)
==
False
:
super
(
SSLConnection
,
self
).
close
()
else
:
pass
def
handle_read_event
(
self
):
if
self
.
_ssl_accepting
:
...
...
@@ -410,12 +413,18 @@ if ssl is not None:
def
__init__
(
self
,
conn
):
DummyFTPHandler
.
__init__
(
self
,
conn
)
self
.
secure_data_channel
=
False
self
.
_ccc
=
False
def
cmd_auth
(
self
,
line
):
"""Set up secure control channel."""
self
.
push
(
'234 AUTH TLS successful'
)
self
.
secure_connection
()
def
cmd_ccc
(
self
,
line
):
self
.
push
(
'220 Reverting back to clear-text'
)
self
.
_ccc
=
True
self
.
_do_ssl_shutdown
()
def
cmd_pbsz
(
self
,
line
):
"""Negotiate size of buffer for secure data transfer.
For TLS/SSL the only valid value for the parameter is '0'.
...
...
@@ -872,6 +881,15 @@ class TestTLS_FTPClass(TestCase):
self
.
assertIs
(
sock
.
context
,
ctx
)
self
.
assertIsInstance
(
sock
,
ssl
.
SSLSocket
)
def
test_ccc
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
client
.
ccc
)
self
.
client
.
login
(
secure
=
True
)
self
.
assertIsInstance
(
self
.
client
.
sock
,
ssl
.
SSLSocket
)
self
.
client
.
ccc
()
self
.
assertRaises
(
ValueError
,
self
.
client
.
sock
.
unwrap
)
self
.
client
.
sendcmd
(
'noop'
)
self
.
client
.
quit
()
class
TestTimeouts
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment