File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 1717
1818try :
1919 from ftplib import FTP_TLS
20- except ImportError :
21- FTP_TLS = None
20+ except ImportError as err :
21+ FTP_TLS = err
2222from ftplib import error_perm
2323from ftplib import error_temp
2424from typing import cast
2525
2626from six import PY2
2727from six import text_type
28+ from six import raise_from
2829
2930from . import errors
3031from .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 )
You can’t perform that action at this time.
0 commit comments