updated
This commit is contained in:
+36
-1
@@ -73,7 +73,7 @@ class FTP(Provider):
|
||||
PLUGIN_NAME = "ftp"
|
||||
URL = ("ftp://", "ftps://")
|
||||
MULTI_INSTANCE = True
|
||||
SUPPORTED_CMDLETS = frozenset({"add-file", "get-file", "search-file"})
|
||||
SUPPORTED_CMDLETS = frozenset({"add-file", "delete-file", "get-file", "search-file"})
|
||||
|
||||
@property
|
||||
def label(self) -> str:
|
||||
@@ -576,6 +576,41 @@ class FTP(Provider):
|
||||
|
||||
return self._build_url(remote_path, settings=settings)
|
||||
|
||||
def delete_file(self, remote_path_or_url: str, **kwargs: Any) -> bool:
|
||||
"""Delete a file from the FTP server.
|
||||
|
||||
Accepts either a full FTP URL (ftp://host/path/file) or a raw remote
|
||||
path (/path/to/file). Returns True on success, False on failure.
|
||||
"""
|
||||
path_text = str(remote_path_or_url or "").strip()
|
||||
if not path_text:
|
||||
return False
|
||||
|
||||
settings = self._resolve_settings(
|
||||
instance_name=str(kwargs.get("instance") or kwargs.get("store") or "").strip() or None,
|
||||
require_explicit=bool(kwargs.get("instance") or kwargs.get("store")),
|
||||
)
|
||||
if not settings.get("host"):
|
||||
requested = str(kwargs.get("instance") or kwargs.get("store") or "").strip()
|
||||
if requested:
|
||||
raise RuntimeError(f"FTP instance '{requested}' is unavailable")
|
||||
raise RuntimeError("No configured FTP instance is available")
|
||||
|
||||
# Accept full FTP URL or raw path
|
||||
if path_text.startswith(("ftp://", "ftps://")):
|
||||
remote_path = self._normalize_remote_path(path_text, default=self._base_path)
|
||||
else:
|
||||
remote_path = self._normalize_remote_path(path_text, default=str(settings.get("base_path") or "/"))
|
||||
|
||||
ftp = self._connect(settings=settings)
|
||||
try:
|
||||
ftp.delete(remote_path)
|
||||
return True
|
||||
except ftplib.error_perm:
|
||||
return False
|
||||
finally:
|
||||
self._close(ftp)
|
||||
|
||||
def _connect(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user