From 3aa8b7aa2d75091cc988e864fb89f344124ebbce Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 14 Aug 2025 20:31:58 +0000 Subject: [PATCH] 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 --- copyparty/ftpd.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/copyparty/ftpd.py b/copyparty/ftpd.py index 004fb492..99b37d26 100644 --- a/copyparty/ftpd.py +++ b/copyparty/ftpd.py @@ -285,9 +285,12 @@ class FtpFs(AbstractedFS): # returning 550 is library-default and suitable raise FSE("No such file or directory") - avfs = vfs.chk_ap(ap, st) - if not avfs: - raise FSE("Permission denied", 1) + if vfs.realpath: + avfs = vfs.chk_ap(ap, st) + if not avfs: + raise FSE("Permission denied", 1) + else: + avfs = vfs self.cwd = nwd ( @@ -492,7 +495,11 @@ class FtpHandler(FTPHandler): def ftp_STOR(self, file: str, mode: str = "w") -> Any: # Optional[str] 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 xbu = vfs.flags.get("xbu") if xbu and not runhook(