Use a Java SSH library like JSch to connect to the remote server. If for some reason you're stuck using Telnet, check out the Apache Commons Net library for a Telnet client. You should NOT use Telnet over a public network, though.
Nipun Bahr wrote:
Can we do the same using Process Builder?
Since ProcessBuilder, like Runtime.exec, can only execute processes locally, that will only work if you have a process such as ssh that you can invoke, so you can invoke that process and tell it to run the remote command. For instance, you might be able to to something like
I leave the research on the details of how to make that work up to you, but one caveat I'll give you is that I don't think ssh likes taking passwords from anything other than a terminal. One way around that is to add your public key to the authorized_keys file on the remote host. You can also research those details yourself.