Skip to content

Commit 2d637f5

Browse files
committed
FTPFS: Raise error in constructor if TLS is enabled but FTP_TLS is not available.
1 parent 5d145cc commit 2d637f5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/ftpfs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
try:
1919
from ftplib import FTP_TLS
20-
except ImportError:
21-
FTP_TLS = None
20+
except ImportError as err:
21+
FTP_TLS = err
2222
from ftplib import error_perm
2323
from ftplib import error_temp
2424
from typing import cast
2525

2626
from six import PY2
2727
from six import text_type
28+
from six import raise_from
2829

2930
from . import errors
3031
from .base import FS
@@ -422,6 +423,9 @@ def __init__(
422423
self.proxy = proxy
423424
self.tls = tls
424425

426+
if self.tls and isinstance(FTP_TLS, Exception):
427+
raise_from(errors.CreateFailed("FTP over TLS not supported"), FTP_TLS)
428+
425429
self.encoding = "latin-1"
426430
self._ftp = None # type: Optional[FTP]
427431
self._welcome = None # type: Optional[Text]
@@ -463,11 +467,7 @@ def _parse_features(cls, feat_response):
463467
def _open_ftp(self):
464468
# type: () -> FTP
465469
"""Open a new ftp object."""
466-
if self.tls and FTP_TLS:
467-
_ftp = FTP_TLS()
468-
else:
469-
self.tls = False
470-
_ftp = FTP()
470+
_ftp = FTP_TLS() if self.tls else FTP()
471471
_ftp.set_debuglevel(0)
472472
with ftp_errors(self):
473473
_ftp.connect(self.host, self.port, self.timeout)

0 commit comments

Comments
 (0)