Skip to content

Commit

Permalink
Add FTPS support for client
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-kuzmenko authored and Alex Kuzmenko committed Oct 11, 2018
1 parent 95cd305 commit 7a4d9f6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions aioftp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
logger = logging.getLogger(__name__)


async def open_connection(host, port, loop, create_connection):
async def open_connection(host, port, loop, create_connection, ssl=None):
reader = asyncio.StreamReader(loop=loop)
protocol = asyncio.StreamReaderProtocol(reader, loop=loop)
transport, _ = await create_connection(lambda: protocol, host, port)
transport, _ = await create_connection(lambda: protocol,
host, port, ssl=ssl)
writer = asyncio.StreamWriter(transport, protocol, reader, loop)
return reader, writer

Expand Down Expand Up @@ -108,7 +109,8 @@ class BaseClient:
def __init__(self, *, loop=None, create_connection=None,
socket_timeout=None, read_speed_limit=None,
write_speed_limit=None, path_timeout=None,
path_io_factory=pathio.PathIO, encoding="utf-8"):
path_io_factory=pathio.PathIO, encoding="utf-8",
ssl=None):
self.loop = loop or asyncio.get_event_loop()
self.create_connection = create_connection or \
self.loop.create_connection
Expand All @@ -122,6 +124,7 @@ def __init__(self, *, loop=None, create_connection=None,
self.path_io = path_io_factory(timeout=path_timeout, loop=loop)
self.encoding = encoding
self.stream = None
self.ssl = ssl

async def connect(self, host, port=DEFAULT_PORT):
self.server_host = host
Expand All @@ -131,6 +134,7 @@ async def connect(self, host, port=DEFAULT_PORT):
port,
self.loop,
self.create_connection,
self.ssl,
)
self.stream = ThrottleStreamIO(
reader,
Expand Down Expand Up @@ -491,6 +495,14 @@ class Client(BaseClient):
:param encoding: encoding to use for convertion strings to bytes
:type encoding: :py:class:`str`
:param ssl: if given and not false, a SSL/TLS transport is created
(by default a plain TCP transport is created).
If ssl is a ssl.SSLContext object, this context is used to create
the transport; if ssl is True, a default context returned from
ssl.create_default_context() is used.
Please look :py:meth:`asyncio.loop.create_connection` docs.
:type ssl: :py:class:`bool` or :py:class:`ssl.SSLContext`
"""
async def connect(self, host, port=DEFAULT_PORT):
"""
Expand Down

0 comments on commit 7a4d9f6

Please sign in to comment.