How can I enable the receipt of 8 bit characters from a SSH connection

Aug 21, 2015 at 5:14 PM

I have been most impressed with SSH.NET, with all the help here I was able to get my terminal emulator to make SSH connections in a short period of time. Well done.

My current issue I have not been able to yet solve. The server program outputs terminal control characters in the range 0x80 to 0xFF. I have tried setting terminal modes in the call to CreateShellStream and I have tried all of the Encoding values in the call to StreamReader constructor. In all cases some if not all of the characters 0x80-0xFF were translated.

Please see my code snippet below.

                    System.Collections.Generic.Dictionary<TerminalModes, uint> tm = new System.Collections.Generic.Dictionary<TerminalModes, uint>();
                    tm[TerminalModes.PARENB] = 0;
                    tm[TerminalModes.ISTRIP] = 0;
                    tm[TerminalModes.CS7] = 0;
                    tm[TerminalModes.CS8] = 1;

                    /* Start the monitor thread which will detect when remote end
                     * closes the connection and will invoke DisconnectEx on this
                     * connection thread */

                    DisconnectEvent += new DisconnectEventHandler(Disconnect);
                    monitorThread = new Thread(monitor);

                    strm = client.CreateShellStream(termType, (uint)tw.Columns, (uint)tw.Rows,
                                                    (uint)tw.ClientSizeEx.Width, (uint)tw.ClientSizeEx.Height, 1024, tm);


                    strm = client.CreateShellStream(termType, (uint)tw.Columns, (uint)tw.Rows,
                                                    (uint)tw.ClientSizeEx.Width, (uint)tw.ClientSizeEx.Height, 1024);


                    //strmReader = new StreamReader(strm);
                    /* Tried these encodings:-
                     * ASCII - >= 0x80-0xFF translated to 0x3F.
                     * Default - 0x80-0x9F : Some set of special Unicode characters, 0xA0-0xFF : unchanged.
                     *           This is using the current Windows ANSI code page. Do I need something like
                     *           code page 8859-1 - Latin alphabet which doesn't seem to translate codes.
                     * Unicode - got a buffer of individual bytes instead of normal 0x61 0x00 etc for each char.
                     * UTF8 - I think this is default. >= 0x80 translated to 0xfffd
                    strmReader = new StreamReader(strm, Encoding.Default);
                    //strmWriter = new StreamWriter(strm);
                    strmWriter = new StreamWriter(strm, Encoding.Default);
Aug 24, 2015 at 5:18 PM
I have solved this problem by supplying an instantiation of my own Encode class, very similar to the the ASCIIEncoding class in Renci.SshNet. It overrides various methods so that bytes are passed through unchanged. I did also get things working by removing the StreamReader/Writers and just using strm.Read and Write, the ConnectionInfo passed in the creation of 'client' needed connectionInfo.Encoding to be set to my encode class.