# Rclone serve sftp + WinSCP background mode uploading causes file corruption

**URL:** <https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841>\
**Category:** Suspected Bug\
**Created:** [May 24, 2026, 9:20am UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841 "2026-05-24T09:20:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shunf4](https://forum.rclone.org/user_avatar/forum.rclone.org/shunf4/32/19929_2.png) [@shunf4](https://forum.rclone.org/u/shunf4)\
**Post date:** [May 24, 2026, 9:20am UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841/1 "2026-05-24T09:20:09Z")

</div>

#### What is the problem you are having with rclone?

When using `rclone serve sftp <local directory>` with WinSCP as the client, uploaded file in **background** mode is corrupted (MD5 hash mismatch; file part at the beginning reset to zero-bits).

Steps to reproduce:

- Run rclone sftp server using the command line below.
- Open WinSCP and connect to it.
- Drag-and-drop a relatively large file (mine is a 19.9 MiB file) into the remote directory view. In the halfway of the upload progress, click "Process In Background" button.
- Wait for it to finish uploading.
- Examine the uploaded file at the server side. It differs from the original file, and a large part of it at the beginning of the file is reset to all zero bits. The percentage of the part approximates the progress where the upload process is scheduled to background.

If the upload is not scheduled to background, the upload file seems intact.

I don't know if it is an issue of WinSCP or rclone, but WinSCP works well with OpenSSH SFTP server with no such problem.

#### Run the command 'rclone version' and share the full output of the command.

rclone v1.75.0-beta.9756.7dcbc8b4f

- os/version: debian 12.14 (64 bit)
- os/kernel: 6.1.0-48-amd64 (x86\_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.26.3
- go/linking: static
- go/tags: none

#### Which cloud storage system are you using? (eg Google Drive)

SFTP serve mode serving a local directory

#### The command you were trying to run (eg `rclone copy /tmp remote:tmp`)

```auto
rclone serve sftp -v -v --user user --authorized-keys /path/to/authorized_keys --addr :30022 --copy-links --vfs-cache-mode=writes --dir-cache-time 0m3s --poll-interval 0m3s --local-encoding=Slash,InvalidUtf8 /srv/test-rclone

```

#### The rclone config contents with secrets removed.

```auto
No config file. /home/user/.config/rclone/rclone.conf does not exist.
No RCLONE_* environment variable exists.
Everything is provided through command line.

```

#### A log from the command with the `-vv` flag

```auto
https://pastebin.com/6uUy4PKG

```

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [May 24, 2026, 12:38pm UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841/2 "2026-05-24T12:38:07Z")

</div>

Thanks for reporting this. Yes this is a bug in rclone to do with it ignoring the Open flags the sftp client is sending which means the file is being truncated when the background operation starts. This explains the corruption (the zero bytes at the start) perfectly.

Here is a fix where we obey the open flags properly - please give it a go!

[v1.75.0-beta.9757.9c9d78ce3.fix-sftp-serve-winscp-resume](https://beta.rclone.org/branch/fix-sftp-serve-winscp-resume/v1.75.0-beta.9757.9c9d78ce3.fix-sftp-serve-winscp-resume/) on branch [fix-sftp-serve-winscp-resume](https://github.com/rclone/rclone/tree/fix-sftp-serve-winscp-resume) (uploaded in 15-30 mins)

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [May 24, 2026, 4:42pm UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841/3 "2026-05-24T16:42:20Z")

</div>

I did a review of the serve sftp source for unimplemented features and I found a few

- open flags (which caused your corruption)
- size ignored in truncate
- statvfs (shows disk usage - it is implemented in the VFS - I don't know why we never plumbed it in - maybe it didn't exist when we made this command in 2019)

So can you try this one instead? Thanks

[v1.75.0-beta.9760.bcb1401c1.fix-sftp-serve-winscp-resume](https://beta.rclone.org/branch/fix-sftp-serve-winscp-resume/v1.75.0-beta.9760.bcb1401c1.fix-sftp-serve-winscp-resume/) on branch [fix-sftp-serve-winscp-resume](https://github.com/rclone/rclone/tree/fix-sftp-serve-winscp-resume) (uploaded in 15-30 mins)

---

<div class="post-metadata">

**Author:** ![shunf4](https://forum.rclone.org/user_avatar/forum.rclone.org/shunf4/32/19929_2.png) [@shunf4](https://forum.rclone.org/u/shunf4)\
**Post date:** [May 25, 2026, 3:06pm UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841/4 "2026-05-25T15:06:12Z")

</div>

I can confirm [v1.75.0-beta.9760.bcb1401c1.fix-sftp-serve-winscp-resume](https://beta.rclone.org/branch/fix-sftp-serve-winscp-resume/v1.75.0-beta.9760.bcb1401c1.fix-sftp-serve-winscp-resume/) fixes the problem. Thanks!

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [May 25, 2026, 7:44pm UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841/5 "2026-05-25T19:44:35Z")

</div>

Thanks for testing @shunf4

I've merged this to master now which means it will be in [the latest beta](https://beta.rclone.org/) in 15-30 minutes and released in v1.75

If we have another point release I'll put the corruption fix in v1.74.3

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [May 28, 2026, 7:45pm UTC](https://forum.rclone.org/t/rclone-serve-sftp-winscp-background-mode-uploading-causes-file-corruption/53841/6 "2026-05-28T19:45:20Z")

</div>

Closed on May 28, 2026, 7:45pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
