w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Interact with linux server using java JSCH

You should set StrictHostKeyChecking property "no" and channel should be set shell.as following.

    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
        }
    }
    else{
        //
    }




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.