If a user places unicode/utf-8 characters into the command the line: buf.putString(command.getBytes());
converts them to non-unicode by doing a command.getBytes() call. I'm having a hard time understanding the reasoning how I figured this out and how is the best way to explain it. However I had implemented a SSHExec command line util and recently I found out that I would be needing to pass unicode(utf-8) characters in my string that comprises my command line. When I sent the command through to the SSH server the command returned back and complained that it only accepted ASCII or UTF-8 characters, given the UTF-8 character I was sending were two \uFF76 characters, I had to search around for means of understanding what my characters were being translated to. I found this page which helped me not understand but to test with the current JSch code a slight change to see if it was correct. http://java.sun.com/docs/books/tutorial/i18n/text/string.html The two things that were pointed out to me on this page was: 1. "To convert the String object to UTF-8, invoke the getBytes method and specify the appropriate encoding identifier as a parameter. The getBytes method returns an array of bytes in UTF-8 format." 2. "If a byte array contains non-Unicode text, you can convert the text to Unicode with one of the String constructor methods. Conversely, you can convert a String object into a byte array of non-Unicode characters with the String.getBytes method." I realize that UTF-8 is most likely not the only character set that would need to be understood for most people. However I only happened to see other references to UTF-8 in the SFTP realm in the mailing lists and in my case I was trying to answer the question as to if my string was getting passed as UTF-8 or not. In my brief test when I changed line 54 of RequestExec.java from: buf.putString(command.getBytes()); to buf.putString(command.getBytes("UTF8")); The command line with UTF-8 characters in it I passed appeared to work as UTF-8 and not as the MS932/CP932 characters that I thought it was converting it to. ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ JSch-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jsch-users
