• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FTPClient storeFile - uploaded file get wrong encoding

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Foreman
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Foreman
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Foreman
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic