ftp: reject uploads nicely; closes #573

if a client tries to upload where it does not have write-access,
rather than kicking the client with an exception, reply properly
This commit is contained in:
ed 2025-08-14 20:31:58 +00:00
parent d56230573d
commit 3aa8b7aa2d

View file

@ -285,9 +285,12 @@ class FtpFs(AbstractedFS):
# returning 550 is library-default and suitable # returning 550 is library-default and suitable
raise FSE("No such file or directory") raise FSE("No such file or directory")
avfs = vfs.chk_ap(ap, st) if vfs.realpath:
if not avfs: avfs = vfs.chk_ap(ap, st)
raise FSE("Permission denied", 1) if not avfs:
raise FSE("Permission denied", 1)
else:
avfs = vfs
self.cwd = nwd self.cwd = nwd
( (
@ -492,7 +495,11 @@ class FtpHandler(FTPHandler):
def ftp_STOR(self, file: str, mode: str = "w") -> Any: def ftp_STOR(self, file: str, mode: str = "w") -> Any:
# Optional[str] # Optional[str]
vp = join(self.fs.cwd, file).lstrip("/") vp = join(self.fs.cwd, file).lstrip("/")
ap, vfs, rem = self.fs.v2a(vp, w=True) try:
ap, vfs, rem = self.fs.v2a(vp, w=True)
except Exception as ex:
self.respond("550 %s" % (ex,), logging.info)
return
self.vfs_map[ap] = vp self.vfs_map[ap] = vp
xbu = vfs.flags.get("xbu") xbu = vfs.flags.get("xbu")
if xbu and not runhook( if xbu and not runhook(