且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Java在远程计算机上执行Linux命令?

更新时间:2022-12-22 22:56:53

Jsch(这里)允许您使用SSH连接到远程服务器并轻松执行shell命令(以及许多其他内容,如SCP,SFTP ......)。没有很多文档,但是您有一些非常有用的实现示例此处(和甚至是你想要做的一个例子这里)。

Jsch (here) allows you to connect to a remote server using SSH and executes shell commands easily (and lot of other things like SCP, SFTP...). There is not a lot of documentation, but you have a few really helpful implementation examples here (and even an example of what you want to do here).

您还可以将Jsch与Expect4j结合使用,这样可以更好地控制您想要执行的命令(很好的示例这里)。

You can also combine Jsch with Expect4j and this way have a better control on the commands you want to execute (nice example here).