Search code examples
javawindowssshjschprintstream

Weird Symbols when connecting to windows througth SSH on java (Jsch)


I am trying to execute a command in windows XP with Jsch Shell channel, but for some reason i get weird symbols in my System.out stream and the commands cannot be executed, the code that i use for connect is this:

this.session = jsch.getSession(this.login, this.host);

Properties properties = new Properties();
properties.put("StrictHostKeyChecking", "no");
session.setPassword(this.password);
session.setConfig(properties);

session.connect(30000);


channel =(ChannelShell) session.openChannel("shell");


PipedInputStream pip = new PipedInputStream(40);
channel.setInputStream(pip);
channel.setOutputStream(System.out);

PipedOutputStream pop = new PipedOutputStream(pip);
print = new PrintStream(pop); 
channel.connect();

Then i get The following message:

[1;1HMicrosoft Windows XP [Versi�n 5.1.2600][2;1H(C) Copyright 1985-2001 Microsoft Corp.[4;1HC:\Documents and Settings\diego\Escritorio>[4;44H

And when i try to call a cd C:\MyFolder\ then another command (all tested from a ssh client and works) i gen more weird symbols and dont get the results of my commands, What can be the problem? Following is the commands that i send and the result:

exec.print.println("cd C:\\MyFolder\\");
exec.print.println("some other command");

result:

[1;1HMicrosoft Windows XP [Versi�n 5.1.2600][2;1H(C) Copyright 1985-2001 Microsoft Corp.[4;1HC:\Documents and Settings\diego\Escritorio>[4;44H[4;1HC:\Documents and Settings\diego\Escritorio>c[4;58H[4;1HC:\Documents and Settings\diego\Escritorio>cd C:\MyFolder\[4;58H[4;46H[4;58H[4;47H[4;58H[4;48H[4;58H[4;49H[4;58H[4;50H[4;58H[4;51H[4;58H[4;52H[4;58H[4;53H[4;58H[4;54H[4;58H[4;55H[4;58H[4;56H[4;58H[4;57H[4;58H

I am using a FreeSShd in windows xp and the program runs on Ubuntu, i use ssh in my console and works with the windows XP, i am trying to implement it in my java program, thanks for any help.


Solution

  • Have you tried direct ssh? If direct ssh works, then its jsch. Try jsch with a linux based ssh server. If jsch works then it is FreeSshd issue.