Skip to content

Commit

Permalink
Rewrite ftp_tls to ftp
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvaneswhiffle committed Apr 22, 2024
1 parent a942021 commit 76a3d2e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 409 deletions.
18 changes: 14 additions & 4 deletions fsspec/implementations/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import uuid
import warnings
from ftplib import FTP, Error, error_perm
from ftplib import FTP, FTP_TLS, Error, error_perm
from typing import Any

from ..spec import AbstractBufferedFile, AbstractFileSystem
Expand All @@ -27,6 +27,8 @@ def __init__(
tempdir=None,
timeout=30,
encoding="utf-8",
ssl=False,
prot_p=False,
**kwargs,
):
"""
Expand Down Expand Up @@ -68,16 +70,24 @@ def __init__(
self.blocksize = block_size
else:
self.blocksize = 2**16
self.ssl = ssl
self.prot_p = prot_p
self._connect()
if self.prot_p:
self.ftp.prot_p()

def _connect(self):
if self.ssl:
ftp_cls = FTP_TLS
else:
ftp_cls = FTP
if sys.version_info >= (3, 9):
self.ftp = FTP(timeout=self.timeout, encoding=self.encoding)
self.ftp = ftp_cls(timeout=self.timeout, encoding=self.encoding)
elif self.encoding:
warnings.warn("`encoding` not supported for python<3.9, ignoring")
self.ftp = FTP(timeout=self.timeout)
self.ftp = ftp_cls(timeout=self.timeout)
else:
self.ftp = FTP(timeout=self.timeout)
self.ftp = ftp_cls(timeout=self.timeout)
self.ftp.connect(self.host, self.port)
self.ftp.login(*self.cred)

Expand Down
Loading

0 comments on commit 76a3d2e

Please sign in to comment.