【发布时间】:2011-11-15 04:21:16
【问题描述】:
我正在 Linux 操作系统中开发 Eclipse,这就是我想要做的(仅在 Java 控制台中)-
- 通过(当前)telnet 客户端连接到另一台远程计算机
- 在远程系统中执行一个简单的命令(类似 ls)
这可能吗?我确定Runtime.getRuntime.exec() 不会工作。所以使用了commons.net jar 文件。这是我的代码 sn-p
public static void testMount() throws Exception {
String osName = "";
Scanner sc = new Scanner(System.in);
TelnetClient telnet = new TelnetClient();
System.out.println("Operating System: ");
osName = sc.next();
System.out.println(osName);
String volumeToMount = "";
String mountPoint = "";
String ipAddress = "";
int port = 23;
if (osName.equalsIgnoreCase("Linux")) {
// Linux
ipAddress = "1.2.3.4"; //
telnet.connect(ipAddress, port);
volumeToMount = "/dev/hda1";
mountPoint = "/data/Temp";
}
mountFileSystem(volumeToMount, mountPoint);
}
如果您有现有示例或者可以修改我的代码,如果您在此处分享,我将不胜感激!
【问题讨论】:
标签: java linux eclipse console telnet