SSH.NET
SSH.NET copied to clipboard
Unwanted UTF-8 with BOM encoding even when using UTF-8 encoding
From our application txt file is getting generated with UTF-8 encoding but while uploading it to SFTP, the file got transformed to UTF-8 with BOM encoding. We are using below code to upload in SFTP and the version of Renci.SshNet that we are using is 2013.4.7.0.
List[AuthenticationMethod] methods;
methods = new List[AuthenticationMethod] { new PasswordAuthenticationMethod(username, password) };
var connectionInfo = new ConnectionInfo(host, port, username, methods.ToArray()); using (SftpClient sftpclient = new SftpClient(connectionInfo)) { sftpclient.Connect(); sftpclient.ChangeDirectory(destinationPath.Trim()); sourceFile.Position = 0; sftpclient.BufferSize = 8 * 1024; sftpclient.UploadFile(sourceFile, fileName); }
Please help to understand why we are facing this problem and what should be the possible fix. Thank you.
Are you able to reproduce the problem using the latest package version (2020.0.2
)? The version you are using is over 10 years old 🙂
How are you creating the file? And validating that is does not have a BOM before the upload but does after? Note that System.Text.Encoding.UTF8
does provide a BOM (https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.utf8?view=net-7.0#remarks).
Are you able to reproduce the problem uploading the file with a different client e.g. WinSCP? Or to a different server?