How can I connect to an SSH server in Java? I don\'t need/want a shell. I just want to connect to the SSH server and get the content of, say, file.txt
. How can
Take a look at Jaramiko.
You must use a third-party library - JSch is one of them. Google with "Java ssh
" and you will get plenty of other options.
Java doesn't support that natively, but you can use a library like JSch to do it
You could check JSSH, which is a Java SSH library.
I used this and worked for me
Channel channel=session.openChannel("exec");
String command = "Your Command here";
((ChannelExec)channel).setCommand(command);
InputStream in=channel.getInputStream();
((ChannelExec)channel).setErrStream(System.err);
channel.connect();
http://www.ganymed.ethz.ch/ssh2/ implements a ssh2 client in Java. I use it for port forwarding.