Skip to content

Commit

Permalink
Remove FTP SSL support and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stxue1 committed Nov 20, 2024
1 parent 59e3fea commit 8fe81cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/toil/jobStores/abstractJobStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,9 @@ class JobStoreSupport(AbstractJobStore, metaclass=ABCMeta):

@classmethod
def _setup_ftp(cls) -> FtpFsAccess:
return FtpFsAccess(insecure=strtobool(os.environ.get('TOIL_FTP_USE_SSL', 'False')) is False)
# FTP connections are not reused. Ideally, a thread should watch any reused FTP connections
# and close them when necessary
return FtpFsAccess()

@classmethod
def _supports_url(cls, url: ParseResult, export: bool = False) -> bool:
Expand Down
19 changes: 3 additions & 16 deletions src/toil/lib/ftp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ class FtpFsAccess:
Taken and modified from https://github.com/ohsu-comp-bio/cwl-tes/blob/03f0096f9fae8acd527687d3460a726e09190c3a/cwl_tes/ftp.py#L37-L251
"""
# TODO: Properly support FTP over SSL

def __init__(
self, cache: Optional[dict[Any, ftplib.FTP]] = None, insecure: bool = False
self, cache: Optional[dict[Any, ftplib.FTP]] = None
):
"""
FTP object to handle FTP connections. By default, connect over FTP with TLS.
:param cache: cache of generated FTP objects
:param insecure: Whether to connect over FTP with TLS
"""
self.cache = cache or {}
self.netrc = None
self.insecure = insecure
try:
if "HOME" in os.environ:
if os.path.exists(os.path.join(os.environ["HOME"], ".netrc")):
Expand Down Expand Up @@ -173,19 +172,7 @@ def _connect(self, url: str) -> Optional[ftplib.FTP]:
user = env_user
if env_passwd:
passwd = env_passwd
try:
# Always try a SSL connection first
ftp.login(user or "", passwd or "", secure=True)
if self.insecure is False:
ftp.prot_p()
except ftplib.error_perm as e:
# SSL failed, consult the insecure flag
if self.insecure:
# If the user has not forced toil to always use SSL, fallback to insecure
ftp.login(user or "", passwd or "", secure=False)
else:
# Else raise an error
raise
ftp.login(user or "", passwd or "", secure=False)
self.cache[(host, user, passwd)] = ftp
return ftp
return None
Expand Down

0 comments on commit 8fe81cc

Please sign in to comment.