XML upload adds ZWNBSP to beginning of file
I have a script that uploads XML files to SFTP using WinSCP.
The issue is that ZWNNBSP is added to the beginning of the files. (Zero Width Non-Breaking Space)
What can I change in my code to solve it?
The issue is that ZWNNBSP is added to the beginning of the files. (Zero Width Non-Breaking Space)
What can I change in my code to solve it?
var sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = ulbcFtpHost, UserName = ulbcFtpUser, Password = ulbcFtpPassword, SshHostKeyPolicy = SshHostKeyPolicy.GiveUpSecurityAndAcceptAny }; using (var session = new Session()) { session.Open(sessionOptions); foreach (FileInfo file in files) { var hasError = false; try { // upload the file TransferOptions transferOptions = new TransferOptions { TransferMode = TransferMode.Binary }; Stream stream = new FileStream(file.FullName, FileMode.Open); session.PutFile(stream, $"{ulbcFtpPath}/{file.Name}", transferOptions); stream.Close(); Logger($"File {file.Name} uploaded successfully to SFTP server."); } catch (Exception ex) { hasError = true; Logger($"Error uploading file: {ex.Message}"); } if (!hasError) { // archive the file try { if (!Directory.Exists(ulbcArchivePath)) { Directory.CreateDirectory(ulbcArchivePath); } var destinationPath = Path.Combine(ulbcArchivePath, file.Name); if (File.Exists(destinationPath)) File.Delete(destinationPath); File.Move(file.FullName, destinationPath); Logger($"File archived: {file.Name}"); } catch (Exception ex) { Logger($"Unable to archive file {file.Name}. {ex.Message}"); } } } }