0 votes
by (120 points)
edited

Hi,

Is there a way to list and download files that have unicode chars in file name?

Our code looks something like this:

Sftp client = new Sftp();

client.Connect("sftp.someserver.com");

client.Login("userName", "password");

client.ChangeDirectory("dirName");

SftpItemCollection list = client.GetList("*.txt");

foreach (SftpItem item in list)    
{    
    ....
    Stream stream = client.GetDownloadStream(item.Name);

    //pass the stream
}

Files that have Chinese symbols as file name are listed as "????.txt" and cannot be downloaded.

I tried switching encoding with:

client.Encoding = System.Text.Encoding.Unicode;

but then I don't get any result.

Thanks

Applies to: Rebex SFTP

1 Answer

0 votes
by (62.7k points)
edited

You have to specify the correct encoding (depending on the FTP server).

From the fact the ASCII characters are displayed correctly (and the Unicode returned no result) I think the encoding of your server is probably UTF8:

client.Encoding = System.Text.Encoding.UTF8;
by (120 points)
edited

Thanks for your answer, but my encoding is "Western European (Windows)" (WebName:Windows-1252), and sftp server is running on windows server. So there you can rename the file using the chinese symbols. I did try changing the encoding at the runtime, but none of them seems to work. Even if I don't try to filter out the results (just use GetList() without args), ASCII, UTF7 and UTF8 throws an exception, while BigEndianUnicode, Unicode, UTF32 returns scrambled results.

by (62.7k points)
edited

Can you please send us the Verbose log of the GetList() method to support@rebex.net? It can be created as follows:

client.Session.LogWriter = new Rebex.FileLogWriter("path", Rebex.LogLevel.Verbose);
client.GetList();
client.Session.LogWriter = null;
...