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

asked 23 Nov '11, 19:40

zmrxac's gravatar image

zmrxac
15
accept rate: 0%

edited 24 Nov '11, 14:24

Lukas%20Matyska's gravatar image

Lukas Matyska ♦♦
90117


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

answered 24 Nov '11, 13:43

Lukas%20Matyska's gravatar image

Lukas Matyska ♦♦
90117
accept rate: 28%

edited 24 Nov '11, 14:23

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.

(28 Nov '11, 20:22) zmrxac

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;
(29 Nov '11, 14:17) Lukas Matyska ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×141
×20
×13

Asked: 23 Nov '11, 19:40

Seen: 456 times

Last updated: 29 Nov '11, 14:17