Tuesday, 6 August 2013

jsch getting InputSTream and OutputStream

jsch getting InputSTream and OutputStream

I am trying SSH client using JSch. Trying to use "exec" Channel
implementation. After successful connection I'm trying to run one command
which will open prompt mode in the server and username and password will
be requested. I observe the username/password always taken from standard
IO (System.in).
I want to get the InputStream and OutPutStream of the server(prompt mode)
so that I can punch in username/password from File rather than in standard
IO.
Below is the code snippet and output:
Sch jsch = new JSch();
Session session=jsch.getSession("user", "host", 22);
session.setPassword("pass");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect(30000);
System.out.println(" Session Connected!!!!!!!!!!!");
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("/opt/nwreg2/local/usrbin/ntcmd");
channel.setInputStream(null);
channel.setOutputStream(null);
InputStream in=channel.getInputStream();//this will not prompt for
username/pass
This will be prompted: username:myuser password:mypass ntcmd>
I want the InputStream and OutputStream to to puch in username/pass and
for ntcmd> prompt.
Let me know any of your thoughts and help.
Thanks Brinal

No comments:

Post a Comment