SSH connection with Java

前端 未结 8 1405
眼角桃花
眼角桃花 2020-12-01 01:40

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

相关标签:
8条回答
  • 2020-12-01 02:01

    Take a look at Jaramiko.

    0 讨论(0)
  • 2020-12-01 02:01

    You must use a third-party library - JSch is one of them. Google with "Java ssh" and you will get plenty of other options.

    0 讨论(0)
  • 2020-12-01 02:02

    Java doesn't support that natively, but you can use a library like JSch to do it

    0 讨论(0)
  • 2020-12-01 02:06

    You could check JSSH, which is a Java SSH library.

    0 讨论(0)
  • 2020-12-01 02:11

    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();
    
    0 讨论(0)
  • 2020-12-01 02:17

    http://www.ganymed.ethz.ch/ssh2/ implements a ssh2 client in Java. I use it for port forwarding.

    0 讨论(0)
提交回复
热议问题