Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FTPClient storeFile - uploaded file get wrong encoding

 
Henrik Samuelsson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I searched the forum to see if someone has had the same problems that I have but did not find any.

Im using Apache FTPClient to connect and upload files and it works fine except for one thing. My application is running on a Linuxmachine which has UTF-8 as default encoding. What happens when I transfer a file stored with i.e. ISO-8859-1 the special chars get messed up. I should also mention that the server is on a windows machine.

This is my answer to why this happens. The storeFile-method take a InputStream which I cant encode(and therefore uses the default encoding. I have tried which Apaches ReaderInputStream bu it didnt work either).

One solution is to set Javas file encoing to ISO-8859-1 but i dont want to do that. Is there any way to dynamic set the encoding when transfering the file? In the same way as in the different reader classes?

Thanks in advance!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds odd: streams do not use any encoding, they just handle bytes. Are you maybe using ASCII mode for the upload? If so, try binary mode; that should leave the file well alone.
 
Henrik Samuelsson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your incredibly quick response.

Yes, I think its strange as well of the same reason as you mentioned. It just bytes. The transfer is made in binarymode. Its very frustrating...
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FTP has 2 data modes, Binary and ASCII.
If you use binary to upload / download Text files, it is likely to destroy the characters.

 
Henrik Samuelsson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you answer.

When I transfer the file in ascii mode the characters looks fine when the file I transfer is stored as UTF-8 but not when its a ISO stored file. This is when the file.encoding is set to the default value (UTF-8).

I think my solution is to set the file.encoding to Iso-8859-1. When its set to iso i can transfer the files binary and it works fine. But I will continue to search for another solution. Because I think I should be able to solve this in code.
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did an activity on character encodings once, and concluded that for business applications UTF-8 suffices almost all the needs as it has all the needed characters and is supported through all layers.

I would want to know the specific requirement for which you need a different encoding set.

Joel's article on character encodings, might divert you a little , but is helpful.
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess your ISOXXXX file does not work because the layers of code that your characters go through during upload are all written for UTF-8
 
Henrik Samuelsson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me it works fine with UTF-8 buts its another application that fetches the uploaded file. And that application can only handle ISO.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic