Reputation: 1377
I am working on eclipse in a Linux OS and this is what i want to do (in the java console only)-
Is that possible? I'm sure Runtime.getRuntime.exec()
wont work. So used the commons.net jar file. Here is my code snippet
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);
}
If you have an existing example or if could modify my code, I'd be thankful to you if you share it over here!
Upvotes: 1
Views: 2719
Reputation: 13574
With Apache Commons Net TelnetClient
you must use the InputStream
and OutputStream
returned by the object (see getInputStream()
and getOutputStream()
method) to read data and send data (commands). A nice example is available here (see section Telnet and Commons/NET).
Upvotes: 4
Reputation: 115398
Why are you implementing Telnet yourself? There are several libraries that do it very well. Take a look on Jakarta Net package: http://commons.apache.org/net/
Upvotes: 0