-
-
Notifications
You must be signed in to change notification settings - Fork 979
Renci.SshNet.Sftp : SftpClient AppendAllText does not work for complex file types such as .docx or .xlsx #1312
Copy link
Copy link
Closed
Description
I have two scenarios to consider.
- I have been trying to use the
appendAllTextfunctionality of the SftpClient to append two .docx files. The steps I perform in sequence are -
- I create a .docx file with some content "First docx".
- I create another .docx file with the content "Second docx".
- I read the second .docx file in bytes and then tried to append the content to the first file by providing the path of the first file. The issue is when I perform the append using the AppendAllText functionality, I end up corrupting the first docx file. It works well for file types such as .txt or .log but for complex file types such as .docx etc it fails.
- The second alternative I am trying is to open the file in a SftpFileStream using the sftpClient.Open method.
- I open the file in the
FileMode.Appendmode and provide the file access asFileAccess.Write, which returns a SftpFileStream. - I open the second Docx file in a memoryStream using
using (var memoryStream = new MemoryStream(byteArrContent))and useawait memoryStream.CopyToAsync(sftpFileStream)to copy the bytes of the second docx to the first one. It also ends up corrupting the docx file.
I wanted to know if append functionality is not supported for such file types, or If I am missing something.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels