List/Download International/Unicode characters in file name

0 votes
asked Nov 23, 2011 by zmrxac (120 points)
edited Nov 29, 2011

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
answered Nov 24, 2011 by Lukas Matyska (54,470 points)
edited Nov 29, 2011

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;
commented Nov 28, 2011 by zmrxac (120 points)
edited Nov 28, 2011

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.

commented Nov 29, 2011 by Lukas Matyska (54,470 points)
edited Nov 29, 2011

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;
...