Jsem zkoušel i toto
http://stackoverflow.com/questions/14323661/simple-ssh-connect-with-jsch
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void spust(View v) throws IOException {
try {
executeRemoteCommand("pi","heslo","192.168.1.5",22);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String executeRemoteCommand(String username,String password,String hostname,int port)
throws Exception {
JSch jsch = new JSch();
Session session = jsch.getSession(username, hostname, port);
session.setPassword(password);
// Avoid asking for key confirmation
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
// SSH Channel
ChannelExec channelssh = (ChannelExec)
session.openChannel("exec");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
channelssh.setOutputStream(baos);
// Execute command
channelssh.setCommand("lsusb > /home/pi/test.txt");
channelssh.connect();
channelssh.disconnect();
return baos.toString();
}
}
Normalně apka funguje ale na raspi se to vubec nepřipojí.
V logech vubec nevídim, že by se to pokoušelo připojít.
Nejnovější komentáře