Android的SSH实例code实例、Android、SSH、code

由网友(知名叔叔)分享简介:我想创建为建立一个SSH会话与远程设备(通过WiFi)和远程设备上执行一些Linux命令的机器人活动。任何人都得到一个快速的,简短的例子,用于连接,验证和发送使用的 Trilead 的图书馆的Andr​​oid? Connectbot源(寻找源代码未维护库中的唯一的地方)是相当广阔和费时的经历如果一个人只是试图做一个快...

我想创建为建立一个SSH会话与远程设备(通过WiFi)和远程设备上执行一些Linux命令的机器人活动。任何人都得到一个快速的,简短的例子,用于连接,验证和发送使用的 Trilead 的图书馆的Andr​​oid? Connectbot源(寻找源代码未维护库中的唯一的地方)是相当广阔和费时的经历如果一个人只是试图做一个快速的SSH连接/命令的执行。我已经找到了sshJ库较早,这已经很好地证明的例子和技巧,但不幸的是Android的缺乏必需的sshJ一些java.util中的类。

我在找Trilead像(这是从sshJ例如我前面发现):

 最后SSHClient SSH =新SSHClient();
ssh.loadKnownHosts();

ssh.connect(本地主机);
尝试 {
    ssh.authPublickey(System.getProperty(user.name));
    最后一次会议会话= ssh.startSession();
    尝试 {
        最后的命令CMD = session.exec(平-c 1 google.com);
        System.out.print(cmd.getOutputAsString());
        的System.out.println(ñ**退出状态:+ cmd.getExitStatus());
    } 最后 {
        session.close();
    }

} 最后 {
    ssh.disconnect();
}
 

解决方案

如果符合你的要求限制你的应用程序到Android 2.3+(姜饼),那么你可以使用sshj。您必须创建与此SSHClient对象 配置。

手机连接Linux系统 JuiceSSH SSH Client Android免费的SSH客户端

I want to create an android activity for setting up an SSH Session with a remote device (through Wifi) and executing some linux commands on the remote device. Anyone got a quick, short example for connecting, authenticating and sending remote commands using Trilead libraries in Android ? Connectbot source (the only place to find the source for the unmaintained library) is quite vast and time consuming to go through if one is just trying to do a quick SSH Connection/ Command execution. I had found the sshJ library earlier, which had nicely documented examples and tips but unfortunately Android lacks some Java.Util classes required for sshJ.

I am looking for something in Trilead like (this is from the sshJ example I found earlier) :

final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();

ssh.connect("localhost");
try {
    ssh.authPublickey(System.getProperty("user.name"));
    final Session session = ssh.startSession();
    try {
        final Command cmd = session.exec("ping -c 1 google.com");
        System.out.print(cmd.getOutputAsString());
        System.out.println("n** exit status: " + cmd.getExitStatus());
    } finally {
        session.close();
    }

} finally {
    ssh.disconnect();
}

解决方案

If you are okay with restricting your app to Android 2.3+ (Gingerbread), then you can use sshj. You will have to create the SSHClient object with this Config.

阅读全文

相关推荐

最新文章