scp via java

前端 未结 15 989
粉色の甜心
粉色の甜心 2020-11-27 13:06

What is the best method of performing an scp transfer via the Java programming language? It seems I may be able to perform this via JSSE, JSch or the bouncy castle java libr

15条回答
  •  一向
    一向 (楼主)
    2020-11-27 13:40

    -: Refining Fernando's answer a little, if you use Maven for dependency management :-

    pom.xml:

    
      org.apache.ant
      ant-jsch
      ${ant-jsch.version}
    
    

    Add this dependency in your project. Latest version can be found here.

    Java code:

    public void scpUpload(String source, String destination) {
        Scp scp = new Scp();
        scp.setPort(port);
        scp.setLocalFile(source);
        scp.setTodir(username + ":" + password + "@" + host + ":" + destination);
        scp.setProject(new Project());
        scp.setTrust(true);
        scp.execute();
    }
    

提交回复
热议问题