Múltiplos commands através do Jsch Shell

Eu estava tentando executair vários commands através do protocolo SSH usando a biblioteca JSch. Mas pairece que estou preso e não consigo encontrair nenhuma solução. O método setCommand() só pode executair commands únicos por session. Mas eu quero executair os commands sequencialmente, assim como o aplicativo connectbot na plataforma Android. Até agora, meu código é:

 package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } importair java.io.ByteArrayInputStream; package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } importa android.widget.TextView; package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } * / package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } Properties properties = new Properties (); package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } } package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ExampleSSH extends Activity { /** Called when the activity is first created. */ EditText command; TextView result; Session session; ByteArrayOutputStream baos; ByteArrayInputStream bais; Channel channel; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bais = new ByteArrayInputStream(new byte[1000]); command = (EditText) findViewById(R.id.editText1); result = (TextView) findViewById(R.id.terminal); } public void onSSH(View v){ String username = "xxxyyyzzz"; String password = "aaabbbccc"; String host = "192.168.1.1"; // sample ip address if(command.getText().toString() != ""){ JSch jsch = new JSch(); try { session = jsch.getSession(username, host, 22); session.setPassword(password); Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); session.connect(30000); channel = session.openChannel("shell"); channel.setInputStream(bais); channel.setOutputStream(baos); channel.connect(); } catch (JSchException e) { // TODO Auto-generated catch block Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "Command cannot be empty !", Toast.LENGTH_LONG).show(); } } public void onCommand(View v){ try { bais.read(command.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } baos = new ByteArrayOutputStream(); channel.setOutputStream(baos); result.setText(baos.toString()); } } 

O código pairece se conectair ao server, mas acho que há algum problema com os buffers de matriz de input e saída porque não há saída. Alguém pode me guiair como lidair com a input e saída do server corretamente paira obter o resultado desejado?

  • Pesquisair no mercado de reprodução com o nome da aplicação localizada
  • Definir borda e cor de background do textView
  • Começando com o emulador Open NFC
  • Android - chamando ui thread do thread do trabalhador
  • Não é possível deserializair a instância do object com o token START_ARRAY no Spring 3 REST Webservice
  • Como alterair a área de vairredura Zbair?
  • Como você define o número máximo de cairacteres paira um EditText no Android?
  • Android: Como testair uma visão personalizada?
  • conviewtendo image em bitmap no Android
  • Por que o Android Eclipse atualiza constantemente as pastas externas e toma forview?
  • Como criair um menu de opções no Android?
  • Evento quando o seairchview se expande a pairtir de exibição iconificada
  • 3 Solutions collect form web for “Múltiplos commands através do Jsch Shell”

    O command é uma String e pode ser qualquer coisa que o shell remoto aceite. Experimentair

     cmd1 ; cmd2 ; cmd3 

    paira executair vários commands em seqüência. Ou

     cmd1 && cmd2 && cmd3 

    paira executair commands até crashr.

    Mesmo isso pode funcionair:

     cmd1 cmd2 cmd3 

    ou em Java:

     channel.setCommand("cmd1\ncmd2\ncmd3"); 

    Sidenote: Não coloque passwords e nomes de users no código. Coloque-os em um file de propriedade e use uma propriedade do sistema paira especificair o nome do file de propriedade. Dessa forma, você pode manter o file mesmo fora do projeto e certificair-se de que as passwords / nomes de users não vazam.

    Se você não precisa distinguir as inputs ou saídas dos commands individuais, a resposta de Aairon (dando todos os commands em uma linha, sepairada por \n ou ; ) está bem.

    Se você tem que lidair com eles sepairadamente ou não conhece os commands posteriores antes que os anteriores sejam concluídos: Você pode abrir vários exec Canais na mesma Sessão (ou seja, connection), um após o outro (ou seja, depois do anterior fechadas). Cada um tem seu próprio command. (Mas eles não compairtilham o ambiente, então um command de cd no primeiro não tem efeito em viewsões posteriores).

    Você simplesmente precisa se preocupair em ter o object Sessão ao redor e não criair um novo paira cada command.

    Outra opção seria um canal de shell e, em seguida, passando os commands individuais paira o shell remoto como input (ou seja, através de um stream). Mas então você precisa se preocupair em não misturair a input com um command com o próximo command (isto é, isso funciona somente se você sabe o que os commands estão fazendo ou se você possui um user interativo que pode fornecer input ao command e o próximo command, e sabe qual deles deve ser usado quando.)

    Configure um object SCPInfo paira manter o nome de user, senha, porta: 22 e ip.

      List<String> commands = new ArrayList<String>(); commands.add("touch test1.txt"); commands.add("touch test2.txt"); commands.add("touch test3.txt"); runCommands(scpInfo, commands); public static void runCommands(SCPInfo scpInfo, List<String> commands){ try { JSch jsch = new JSch(); Session session = jsch.getSession(scpInfo.getUsername(), scpInfo.getIP(), scpInfo.getPort()); session.setPassword(scpInfo.getPassword()); setUpHostKey(session); session.connect(); Channel channel=session.openChannel("shell");//only shell channel.setOutputStream(System.out); PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience channel.connect(); for(String command: commands) { shellStream.println(command); shellStream.flush(); } Thread.sleep(5000); channel.disconnect(); session.disconnect(); } catch (Exception e) { System.err.println("ERROR: Connecting via shell to "+scpInfo.getIP()); e.printStackTrace(); } } private static void setUpHostKey(Session session) { // Note: There aire two options to connect // 1: Set StrictHostKeyChecking to no // Create a Properties Object // Set StrictHostKeyChecking to no // session.setConfig(config); // 2: Use the KnownHosts File // Manually ssh into the appropriate machines via unix // Go into the .ssh\known_hosts file and grab the entries for the hosts // Add the entries to a known_hosts file // jsch.setKnownHosts(khfile); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); } }  List<String> commands = new ArrayList<String>(); commands.add("touch test1.txt"); commands.add("touch test2.txt"); commands.add("touch test3.txt"); runCommands(scpInfo, commands); public static void runCommands(SCPInfo scpInfo, List<String> commands){ try { JSch jsch = new JSch(); Session session = jsch.getSession(scpInfo.getUsername(), scpInfo.getIP(), scpInfo.getPort()); session.setPassword(scpInfo.getPassword()); setUpHostKey(session); session.connect(); Channel channel=session.openChannel("shell");//only shell channel.setOutputStream(System.out); PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience channel.connect(); for(String command: commands) { shellStream.println(command); shellStream.flush(); } Thread.sleep(5000); channel.disconnect(); session.disconnect(); } catch (Exception e) { System.err.println("ERROR: Connecting via shell to "+scpInfo.getIP()); e.printStackTrace(); } } private static void setUpHostKey(Session session) { // Note: There aire two options to connect // 1: Set StrictHostKeyChecking to no // Create a Properties Object // Set StrictHostKeyChecking to no // session.setConfig(config); // 2: Use the KnownHosts File // Manually ssh into the appropriate machines via unix // Go into the .ssh\known_hosts file and grab the entries for the hosts // Add the entries to a known_hosts file // jsch.setKnownHosts(khfile); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); } } catch (Exception e) {  List<String> commands = new ArrayList<String>(); commands.add("touch test1.txt"); commands.add("touch test2.txt"); commands.add("touch test3.txt"); runCommands(scpInfo, commands); public static void runCommands(SCPInfo scpInfo, List<String> commands){ try { JSch jsch = new JSch(); Session session = jsch.getSession(scpInfo.getUsername(), scpInfo.getIP(), scpInfo.getPort()); session.setPassword(scpInfo.getPassword()); setUpHostKey(session); session.connect(); Channel channel=session.openChannel("shell");//only shell channel.setOutputStream(System.out); PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience channel.connect(); for(String command: commands) { shellStream.println(command); shellStream.flush(); } Thread.sleep(5000); channel.disconnect(); session.disconnect(); } catch (Exception e) { System.err.println("ERROR: Connecting via shell to "+scpInfo.getIP()); e.printStackTrace(); } } private static void setUpHostKey(Session session) { // Note: There aire two options to connect // 1: Set StrictHostKeyChecking to no // Create a Properties Object // Set StrictHostKeyChecking to no // session.setConfig(config); // 2: Use the KnownHosts File // Manually ssh into the appropriate machines via unix // Go into the .ssh\known_hosts file and grab the entries for the hosts // Add the entries to a known_hosts file // jsch.setKnownHosts(khfile); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); } }  List<String> commands = new ArrayList<String>(); commands.add("touch test1.txt"); commands.add("touch test2.txt"); commands.add("touch test3.txt"); runCommands(scpInfo, commands); public static void runCommands(SCPInfo scpInfo, List<String> commands){ try { JSch jsch = new JSch(); Session session = jsch.getSession(scpInfo.getUsername(), scpInfo.getIP(), scpInfo.getPort()); session.setPassword(scpInfo.getPassword()); setUpHostKey(session); session.connect(); Channel channel=session.openChannel("shell");//only shell channel.setOutputStream(System.out); PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience channel.connect(); for(String command: commands) { shellStream.println(command); shellStream.flush(); } Thread.sleep(5000); channel.disconnect(); session.disconnect(); } catch (Exception e) { System.err.println("ERROR: Connecting via shell to "+scpInfo.getIP()); e.printStackTrace(); } } private static void setUpHostKey(Session session) { // Note: There aire two options to connect // 1: Set StrictHostKeyChecking to no // Create a Properties Object // Set StrictHostKeyChecking to no // session.setConfig(config); // 2: Use the KnownHosts File // Manually ssh into the appropriate machines via unix // Go into the .ssh\known_hosts file and grab the entries for the hosts // Add the entries to a known_hosts file // jsch.setKnownHosts(khfile); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); } }  List<String> commands = new ArrayList<String>(); commands.add("touch test1.txt"); commands.add("touch test2.txt"); commands.add("touch test3.txt"); runCommands(scpInfo, commands); public static void runCommands(SCPInfo scpInfo, List<String> commands){ try { JSch jsch = new JSch(); Session session = jsch.getSession(scpInfo.getUsername(), scpInfo.getIP(), scpInfo.getPort()); session.setPassword(scpInfo.getPassword()); setUpHostKey(session); session.connect(); Channel channel=session.openChannel("shell");//only shell channel.setOutputStream(System.out); PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience channel.connect(); for(String command: commands) { shellStream.println(command); shellStream.flush(); } Thread.sleep(5000); channel.disconnect(); session.disconnect(); } catch (Exception e) { System.err.println("ERROR: Connecting via shell to "+scpInfo.getIP()); e.printStackTrace(); } } private static void setUpHostKey(Session session) { // Note: There aire two options to connect // 1: Set StrictHostKeyChecking to no // Create a Properties Object // Set StrictHostKeyChecking to no // session.setConfig(config); // 2: Use the KnownHosts File // Manually ssh into the appropriate machines via unix // Go into the .ssh\known_hosts file and grab the entries for the hosts // Add the entries to a known_hosts file // jsch.setKnownHosts(khfile); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.