I am connecting to the remote server SSH server and trying to get get the list of files in a particular path I am able to get list of files in the path but they were in unreadable format could any one help on this
String host="xxxxx.yyyy.com";
String user="user";
String password="password";
String command1="dzdo su - lucy";
try{
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println("Connected");
Channel channel=session.openChannel("shell");
OutputStream ops = channel.getOutputStream();
PrintStream ps = new PrintStream(ops, true);
channel.connect();
ps.println(command1);
ps.println("ls -ltr");
InputStream in=channel.getInputStream();
byte[] tmp=new byte[1024];
while(true){
while(in.available()>0){
int i=in.read(tmp, 0, 1024);
if(i<0)break;
System.out.print(new String(tmp, 0, i));
}
if(channel.isClosed()){
System.out.println("exit-status: "+channel.getExitStatus());
break;
}
try{Thread.sleep(1000);}catch(Exception ee){}
}
channel.disconnect();
session.disconnect();
System.out.println("DONE");
Here is the console output
drwxrws---. 2 gleaiid gleai 4096 Jan 21 2016 [0m[01;34mold[0m
-rwxrws---. 1 jhon gleai 100 Jul 20 2017 [30;43mNVISAP_814_Test.txt[0m
-rwxrws---. 1 jhon gleai 134 Jul 20 2017 [30;43mUS_NISC14_4164556_Test.txt[0m
-rwxrws---. 1 jhon gleai 0 Jul 20 2017 [30;43mNVISAP_R00814_Test.trg[0m