title: Sending commands to server via JSch shell channel
body: <p>I can't figure it out how I can send commands via JSch shell channel.</p>
  
  <p>I do this, but it doesn't work:</p>
  
  <pre><code>JSch shell = new JSch();
  String command = "cd home/s/src";  
  Session session = shell.getSession(username, host, port);  
  MyUserInfo ui = new MyUserInfo();  
  ui.setPassword(password);  
  session.setUserInfo(ui);  
  session.connect();  
  
  channel = session.openChannel("shell");  
  fromServer = new BufferedReader(new InputStreamReader(channel.getInputStream()));  
  toServer = channel.getOutputStream();
  channel.connect();  
  toServer.write((command + "\r\n").getBytes());
  toServer.flush();
  </code></pre>
  
  <p>and then I read input like this:</p>
  
  <pre><code>StringBuilder builder = new StringBuilder();  
  
  int count = 0;  
  String line = "";  
  
  while(line != null) {  
      line = fromServer.readLine();
      builder.append(line).append("\n");
  
      if (line.endsWith(".") || line.endsWith("&gt;")){
          break;
      }
  }  
  String result = builder.toString();  
  ConsoleOut.println(result);
  </code></pre>