4

I am currently using Renci.SshNet to upload files and directories using SFTP, and everything works fine so far, except for encoding issues when copying files containing special character, like the German letters ß, ä. ö. ü, and so on.

For example, when I try to upload a directory called "Fünf", the name is transcripted to "Fünf".

Is there any kind of encoding I need to enable or set so that my strings will arrive correctly?

using (var sftp = new SftpClient(host, username, password))
{
      sftp.Connect();
      Stream file3 = File.OpenRead(localFileName);
      var result = sftp.BeginUploadFile(file3, remoteFileName) as SftpUploadAsyncResult;
}

1 Answer 1

5

The SSH.NET defaults to UTF-8 encoding.

Your SFTP server possibly uses a different encoding (maybe ISO-8859-1).

To make SSH.NET use a non-UTF-8 encoding, use an overload of SftpClient constructor that takes ConnectionInfo:

public SftpClient(ConnectionInfo connectionInfo)

And set the ConnectionInfo.Encoding as needed.


Example code that you ended up using:

var meth = new PasswordAuthenticationMethod(username, password);
ConnectionInfo myConnectionInfo = new ConnectionInfo(host, 22, username, meth); 
myConnectionInfo.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

using (var sftp = new SftpClient(myConnectionInfo))
{ 
    sftp.Connect();
    ....
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.