Skip to content

Conversation

@Rob-Hague
Copy link
Collaborator

SftpClient.CreateText does not truncate the file if it exists, contrary to System.IO.File.CreateText which does. It is documented, but seems pretty unintuitive and more like a mistake than a concious decision (the documentation was added much later than the implementation).

I considered leaving this 14 year old behaviour as it is, but turns out other people have hit it as well (it also affects WriteAll{Bytes/Text/Lines}).

closes #275

SftpClient.CreateText does not truncate the file if it exists, contrary to
System.IO.File.CreateText which does. It is documented, but seems pretty
unintuitive and more like a mistake than a concious decision.

I considered leaving this 14 year old behaviour as it is, but turns out other
people have hit it as well (it also affects WriteAll{Bytes/Text/Lines}).
@Rob-Hague Rob-Hague merged commit 6cba1be into sshnet:develop Aug 10, 2025
4 checks passed
@Rob-Hague Rob-Hague deleted the createtext branch August 10, 2025 15:11
@Rob-Hague
Copy link
Collaborator Author

Thanks

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.

SftpClient: Modify methods that overwrite existing file to first truncate the file

2 participants