Skip to content

serve ftp: fix APPE and resumed uploads destroying the existing file - #10403

Open
r0h1tb wants to merge 1 commit into
rclone:masterfrom
r0h1tb:fix/serve-ftp-append
Open

r0h1tb wants to merge 1 commit into
rclone:masterfrom
r0h1tb:fix/serve-ftp-append

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What does this change do?

rclone serve ftp destroys data when a client appends to a file or resumes an upload, and reports success.

  • APPE removes the existing file and stores only the appended bytes. goftp calls PutFile with the same offset (-1) for APPE as for STOR, so it takes the "new upload" branch. curl --append loses what was there, and curl -C - (SIZE then APPE) leaves only the tail: a 100000 byte upload resumed after 5000 bytes ends up 95000 bytes.
  • REST n + STOR with a VFS cache opens the file O_APPEND|O_RDWR and then seeks. With O_APPEND every write goes to the end, so REST 6 + STOR "WORLD" onto hello world gives hello worldWORLD instead of hello WORLD.
rclone serve ftp dir --addr 127.0.0.1:2121 --user u --pass p --vfs-cache-mode writes
printf 'hello ' > a.txt; printf 'world' > b.txt
curl -T a.txt ftp://u:[email protected]:2121/f.txt
curl --append -T b.txt ftp://u:[email protected]:2121/f.txt
curl ftp://u:[email protected]:2121/f.txt   # "world", expected "hello world"

The fix appends from the end of an existing file when the command is APPE, and opens the file O_RDWR so the seek to the restart offset takes effect. Data after the written range is kept, as vsftpd does.

One behaviour change: with --vfs-cache-mode off, APPE onto an existing file now fails with a 450 error, like REST+STOR already does in that mode, instead of replacing the file. APPE to a new file still works in every mode.

Tests: TestUploadOffset covers APPE to a new and to an existing file, and REST at the end and in the middle of a file, checking both the download and the file on disk. Without the fix Append gets " again" and RestartInMiddle gets "hello worldWORLD". The test file is excluded on darwin, so I ran it on macOS with the build tag lifted locally: the package's existing tests fail and pass the same with and without the change. I also checked APPE and curl -C - resumes end to end against a built binary in off and writes cache modes.

Linked issue

None, found while testing serve ftp uploads.

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.
  • This Pull Request is ready for review.

APPE deleted the existing file and stored only the appended data, so
`curl --append` and upload resumes such as `curl -C -` lost everything
already on the server while reporting success. The ftp library passes
APPE the same offset as STOR, so PutFile now appends from the end of
an existing file itself.

REST followed by STOR opened the file with O_APPEND, which made every
write go to the end of the file and the seek to the restart offset had
no effect. Open it O_RDWR instead so the data lands at the offset.

With --vfs-cache-mode off, APPE onto an existing file now fails with an
error, as REST+STOR already did, instead of replacing the file.
@r0h1tb
r0h1tb requested review from albertony and ncw as code owners November 21, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant