aspose file tools*
The moose likes I/O and Streams and the fly likes FTPClient storeFile - uploaded file get wrong encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "FTPClient storeFile - uploaded file get wrong encoding" Watch "FTPClient storeFile - uploaded file get wrong encoding" New topic
Author

FTPClient storeFile - uploaded file get wrong encoding

Henrik Samuelsson
Greenhorn

Joined: Jun 10, 2008
Posts: 6
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
Marshal

Joined: Mar 22, 2005
Posts: 41904
    
  63
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.


Ping & DNS - my free Android networking tools app
Henrik Samuelsson
Greenhorn

Joined: Jun 10, 2008
Posts: 6
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

Joined: Jul 29, 2008
Posts: 275

FTP has 2 data modes, Binary and ASCII.
If you use binary to upload / download Text files, it is likely to destroy the characters.


Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
Henrik Samuelsson
Greenhorn

Joined: Jun 10, 2008
Posts: 6
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

Joined: Jul 29, 2008
Posts: 275

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

Joined: Jul 29, 2008
Posts: 275

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

Joined: Jun 10, 2008
Posts: 6
For me it works fine with UTF-8 buts its another application that fetches the uploaded file. And that application can only handle ISO.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FTPClient storeFile - uploaded file get wrong encoding