fix(ftp): recursively delete directory contents before RMD

Problem: FTP's RMD command fails with '550 Directory not empty'
if the directory has any contents. Unlike the S3 adapter which uses
`aws s3 rm --recursive`, FTP has no protocol-level recursive delete.

Solution: emit a Python rmtree helper inside the ftpcmd script that
walks the directory via MLSD, recursively deletes children (DELE for
files, rmtree for subdirs), then sends RMD on the now-empty directory.
This commit is contained in:
Barrett Ruth 2026-03-17 22:20:32 -04:00
parent c90c5fcfaa
commit b7f475787e
Signed by: barrett
GPG key ID: A6C96C9349D2FC81

View file

@ -496,7 +496,16 @@ M.perform_action = function(action, cb)
local res = M.parse_url(action.url)
local ftp_path = ftp_abs_path(res)
if action.entry_type == 'directory' then
ftpcmd(res, { string.format('ftp.voidcmd(%q)', 'RMD ' .. ftp_path) }, cb)
ftpcmd(res, {
'def rmtree(f, p):',
' for name, facts in f.mlsd(p):',
' if name in (".", ".."): continue',
' child = p.rstrip("/") + "/" + name',
' if facts["type"] == "dir": rmtree(f, child)',
' else: f.voidcmd("DELE " + child)',
' f.voidcmd("RMD " + p)',
string.format('rmtree(ftp, %q)', ftp_path),
}, cb)
else
ftpcmd(res, { string.format('ftp.voidcmd(%q)', 'DELE ' .. ftp_path) }, cb)
end