mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
ftp: support touch+write, windows-login, verbosity
This commit is contained in:
parent
6c962ec7d3
commit
53b32f97e8
|
@ -693,6 +693,7 @@ def run_argparse(
|
||||||
ap2.add_argument("--ftp", metavar="PORT", type=int, help="enable FTP server on PORT, for example \033[32m3921")
|
ap2.add_argument("--ftp", metavar="PORT", type=int, help="enable FTP server on PORT, for example \033[32m3921")
|
||||||
ap2.add_argument("--ftps", metavar="PORT", type=int, help="enable FTPS server on PORT, for example \033[32m3990")
|
ap2.add_argument("--ftps", metavar="PORT", type=int, help="enable FTPS server on PORT, for example \033[32m3990")
|
||||||
ap2.add_argument("--ftpv", action="store_true", help="verbose")
|
ap2.add_argument("--ftpv", action="store_true", help="verbose")
|
||||||
|
ap2.add_argument("--ftp-wt", metavar="SEC", type=int, default=7, help="grace period for resuming interrupted uploads (any client can write to any file last-modified more recently than SEC seconds ago)")
|
||||||
ap2.add_argument("--ftp-nat", metavar="ADDR", type=u, help="the NAT address to use for passive connections")
|
ap2.add_argument("--ftp-nat", metavar="ADDR", type=u, help="the NAT address to use for passive connections")
|
||||||
ap2.add_argument("--ftp-pr", metavar="P-P", type=u, help="the range of TCP ports to use for passive connections, for example \033[32m12000-13000")
|
ap2.add_argument("--ftp-pr", metavar="P-P", type=u, help="the range of TCP ports to use for passive connections, for example \033[32m12000-13000")
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,7 @@ class FtpAuth(DummyAuthorizer):
|
||||||
if username == "anonymous":
|
if username == "anonymous":
|
||||||
uname = "*"
|
uname = "*"
|
||||||
else:
|
else:
|
||||||
creds = password or username
|
uname = asrv.iacct.get(password, "") or asrv.iacct.get(username, "") or "*"
|
||||||
uname = asrv.iacct.get(creds, "") if creds else "*"
|
|
||||||
|
|
||||||
if not uname or not (asrv.vfs.aread.get(uname) or asrv.vfs.awrite.get(uname)):
|
if not uname or not (asrv.vfs.aread.get(uname) or asrv.vfs.awrite.get(uname)):
|
||||||
g = self.hub.gpwd
|
g = self.hub.gpwd
|
||||||
|
@ -164,8 +163,15 @@ class FtpFs(AbstractedFS):
|
||||||
w = "w" in mode or "a" in mode or "+" in mode
|
w = "w" in mode or "a" in mode or "+" in mode
|
||||||
|
|
||||||
ap = self.rv2a(filename, r, w)
|
ap = self.rv2a(filename, r, w)
|
||||||
if w and bos.path.exists(ap):
|
if w:
|
||||||
raise FilesystemError("cannot open existing file for writing")
|
try:
|
||||||
|
st = bos.stat(ap)
|
||||||
|
td = time.time() - st.st_mtime
|
||||||
|
except:
|
||||||
|
td = 0
|
||||||
|
|
||||||
|
if td < -1 or td > self.args.ftp_wt:
|
||||||
|
raise FilesystemError("cannot open existing file for writing")
|
||||||
|
|
||||||
self.validpath(ap)
|
self.validpath(ap)
|
||||||
return open(fsenc(ap), mode)
|
return open(fsenc(ap), mode)
|
||||||
|
@ -273,8 +279,11 @@ class FtpFs(AbstractedFS):
|
||||||
return bos.lstat(ap)
|
return bos.lstat(ap)
|
||||||
|
|
||||||
def isfile(self, path: str) -> bool:
|
def isfile(self, path: str) -> bool:
|
||||||
st = self.stat(path)
|
try:
|
||||||
return stat.S_ISREG(st.st_mode)
|
st = self.stat(path)
|
||||||
|
return stat.S_ISREG(st.st_mode)
|
||||||
|
except:
|
||||||
|
return False # expected for mojibake in ftp_SIZE()
|
||||||
|
|
||||||
def islink(self, path: str) -> bool:
|
def islink(self, path: str) -> bool:
|
||||||
ap = self.rv2a(path)
|
ap = self.rv2a(path)
|
||||||
|
@ -326,6 +335,9 @@ class FtpHandler(FTPHandler):
|
||||||
# abspath->vpath mapping to resolve log_transfer paths
|
# abspath->vpath mapping to resolve log_transfer paths
|
||||||
self.vfs_map: dict[str, str] = {}
|
self.vfs_map: dict[str, str] = {}
|
||||||
|
|
||||||
|
# reduce non-debug logging
|
||||||
|
self.log_cmds_list = [x for x in self.log_cmds_list if x not in ("CWD", "XCWD")]
|
||||||
|
|
||||||
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("/")
|
||||||
|
|
Loading…
Reference in a new issue