Results 1 to 2 of 2
  1. #1
    abi3719 is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default JSCh Connectivity Problem

    Hi,

    I use JSCh jar file, to connect to remote unix host and execute commands. But, the following code snippet has a problem :

    session = jsch.getSession(user,host_name,22);
    System.out.println("Session created");
    UserInfo usrInfo=new MyUserInfo();
    session.setUserInfo(usrInfo);
    session.connect();
    Channel channel=session.openChannel("exec");
    ((ChannelExec) channel).setCommand(cmd);
    channel.setXForwarding(true);
    InputStream in;
    in = channel.getInputStream();
    System.out.println("Input stream is:"+channel.getInputStream());
    channel.connect();
    System.out.println("Channel Initiated");
    channel.setInputStream(System.in);
    System.out.println("Channel set io stream done successfully");
    byte[] tmp = new byte[1024];
    while (true)
    {
    while (in.available() > 0)
    {
    System.out.println("I enter this while");
    int i = in.read(tmp, 0, 1024);
    if (i < 0)
    break;
    s = new String(tmp, 0, i);
    System.out.print("The String returned is: "+s);
    }


    This code snippet works, when i debug it. But, when i run the same, it doesnt run as expected. I found out, the problem is with the channel. The channel gets closed unexpectedly, and thats why the 'while' loop (in bold), doesnt gets executed. Kindly help.Thanks.

  2. #2
    s2sgateway is offline Member
    Join Date
    Sep 2010
    Posts
    17
    Rep Power
    0

Similar Threads

  1. problem in sql connectivity
    By Bharati in forum JDBC
    Replies: 3
    Last Post: 03-26-2010, 06:50 PM
  2. Replies: 5
    Last Post: 01-28-2010, 12:34 PM
  3. JSch 0.1.38
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-24-2008, 06:50 PM
  4. JSch 0.1.36
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-30-2007, 06:05 PM
  5. JSch 0.1.33
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-11-2007, 09:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •