SSH connection with Java

前端 未结 8 1490
眼角桃花
眼角桃花 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: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();
    

提交回复
热议问题