Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.6k views
in .NET FTP by
Some people ask about non-latin charset support.

My solution(csharp):

1. file: FTPClient.cs:

Find(method Dir()):

// get a character input stream to read data from .
                    StreamReader input = new StreamReader(data.DataStream);


and

add this param:

Encoding.GetEncoding("your charset")

// get a character input stream to read data from .
                    StreamReader input = new StreamReader(data.DataStream, Encoding.GetEncoding("your charset"));


2. file: FTPControlSocket.cs:

Find(InitStreams()):

writer = new StreamWriter(stream, Encoding.GetEncoding("US-ASCII"));
reader = new StreamReader(stream, Encoding.GetEncoding("US-ASCII"));


and change param:

Encoding.GetEncoding("US-ASCII")

to

Encoding.GetEncoding("your charset")

writer = new StreamWriter(stream, Encoding.GetEncoding("your charset")"));            
reader = new StreamReader(stream, Encoding.GetEncoding("your charset")"));


that's all:)

3. rebuild project.

==========================================

todo:

dynamicaly determine ftp server charset and encode data

2 Answers

0 votes
by
0 votes
by
There's more that needs to be done to this...

In FTPClient.cs

in the method
PutASCII(Stream srcStream, string remoteFile, bool append)

the 2 streams input and output also needs to have a proper encoding
or else uploaded files' character-set-specific characters will be removed.

It woule make a lot of sense to be able to assign the whole FTP class
an encoding from the outside so you can control this in addition to which
transfer type is being used, i.e. ASCII/binary...

It's only 5 places anyway..

Or you can do it like this:

input = new StreamReader(srcStream,System.Text.Encoding.GetEncoding(0));

then the default encoding will be used which is way better than defaulting to US encoding which instead is quite horrible!!!!

Something to do in version 1.2.3? ;)

Categories

...