Converting string into inputstream and outputstream Jsch (ssh connection)
845781Mar 14 2011 — edited Mar 14 2011hi,
I'm not really sure if this is the place where i should ask this, but if it is so then tell me!
So my problem is that everything works just fine with input output streams like in this code, but i need to change this input stream into string messadge(Which would work!!)
The main problem is not that i can't change string to inputstream, but that when i use inputstream every commands works, and when i try to do the same with sting>inputstream this doesn't work...
unfortunatelly newgrp server; or newgrp doesn't rerally work just frezzes :/
anyway i solved the initial problem, because Jsch have two (probably more methods of sending info to unix server, but because there is no documentation htere no way to know :D)
methods of sending info to server : exec and shell , the exec sends one command and only works with commands like date;ls... now the shell can easily send any type of command including newgrp server1, and everything works :)
so we connect to the server(passw,user,host) then excecute commands, this code works perfectle but the commented code// doesn't work :
JSch jsch=new JSch();
String host=null;
String user="me1234";
host="super.server.co.uk";
String passw="12345";
Session session=jsch.getSession(user, host, 22);
session.setPassword(passw);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel=session.openChannel("shell"); //the power of shell, if i use exec doesn't excecute newgrp...
//String command = "newgrp xxxx;"; //this doesn't work ...
//InputStream is = new ByteArrayInputStream(command.getBytes("UTF-8"));
//channel.setInputStream(is);
//then somehow printout the response from server...
channel.setInputStream(System.in); // well instead of this I'd prefer channel.send(command);
channel.setOutputStream(System.out);
channel.connect();
Edited by: 842778 on 14-Mar-2011 01:42