How to specify encoding for file transfer from FTP?

K

K Viltersten

I noticed that when i read files from an FTP
using FtpWebRequest, the file names using
swedish characters seem not to be interpreted
correctly. I get a square, instead.

After having looked for an hour or so, i gave
up - where do i specify the encoding for the
communication with the FTP server?
 
A

Arne Vajhøj

K said:
I noticed that when i read files from an FTP
using FtpWebRequest, the file names using
swedish characters seem not to be interpreted
correctly. I get a square, instead.

After having looked for an hour or so, i gave
up - where do i specify the encoding for the
communication with the FTP server?

If you get a file binary with Stream's then you do not
care about encoding.

If you get a file text with StreamReader and StreamWriter
then those two classes has constructors that takes an
Encoding as argument.

Arne
 
K

K Viltersten

I noticed that when i read files from an FTP
If you get a file binary with Stream's then you do not
care about encoding.

If you get a file text with StreamReader and StreamWriter
then those two classes has constructors that takes an
Encoding as argument.

Thanks. I still have two problems. I'd go with
the binary style, however, i'm reading the list
of all files using
WebRequestMethods.Ftp.ListDirectory;
and i don't know the size of the result. What
size of the buffer need i to declare?

Also, when i tried to read the contents of the
stream, i got an exception.
System.Net.ProtocolViolationException
What to do?

My hypothesis is that i can't read binary using
ListDirectory method. Is that true?
 
A

Arne Vajhøj

K said:
Thanks. I still have two problems. I'd go with
the binary style, however, i'm reading the list
of all files using
WebRequestMethods.Ftp.ListDirectory;
and i don't know the size of the result. What
size of the buffer need i to declare?

You don't.

You will need to read to end of file.

StreamReader and ReadToEnd is easy.
Also, when i tried to read the contents of the
stream, i got an exception.
System.Net.ProtocolViolationException
What to do?

My hypothesis is that i can't read binary using
ListDirectory method. Is that true?

I think so.

Arne
 
K

K Viltersten

Thanks. I still have two problems. I'd go with
You don't.

You will need to read to end of file.

StreamReader and ReadToEnd is easy.


I think so.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top