I am uploading a Unicode-encoded file from Windows to a Unix SFTP server via the following code:
using (Sftp sftp = new Sftp())
{
// Settings
sftp.Timeout = requestTimeout;
sftp.ServerType = SftpServerType.Unix;
sftp.TransferType = SftpTransferType.Ascii;
// Connect to SFTP server
sftp.Connect(serverHostname);
// Login
SshPrivateKey privateKey = new SshPrivateKey(privateKeyPath, "");
sftp.Login(username, privateKey);
// Upload the file
sftp.PutFile(localFilePath, remoteFilePath);
}
However, the file gets uploaded to the server with "ÿþ" at the beginning of the document, and "^M" at the end of each line--it appears it did not get encoded properly.
For example, I can create a file using the following code:
string tempPath = Path.GetTempFileName();
string[] lines = new string[]
{
"this is line 1",
"this is line 1",
"this is line 1",
"this is line 4"
};
File.WriteAllLines(tempPath, lines, Encoding.Unicode);
When I upload it, what I see on the server is:
ÿþthis is line 1^M
this is line 1^M
this is line 1^M
this is line 4^M
What could be causing this to happen? I am using version 2.0.4086.0 of Rebex.Net.Sftp.dll