scp via java

前端 未结 15 990
粉色の甜心
粉色の甜心 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:51

    I looked at a lot of these solutions and didn't like many of them. Mostly because the annoying step of having to identify your known hosts. That and JSCH is at a ridiculously low level relative to the scp command.

    I found a library that doesn't require this but it's bundled up and used as a command line tool. https://code.google.com/p/scp-java-client/

    I looked through the source code and discovered how to use it without the command line. Here's an example of uploading:

        uk.co.marcoratto.scp.SCP scp = new uk.co.marcoratto.scp.SCP(new uk.co.marcoratto.scp.listeners.SCPListenerPrintStream());
        scp.setUsername("root");
        scp.setPassword("blah");
        scp.setTrust(true);
        scp.setFromUri(file.getAbsolutePath());
        scp.setToUri("root@host:/path/on/remote");
        scp.execute();
    

    The biggest downside is that it's not in a maven repo (that I could find). But, the ease of use is worth it to me.

提交回复
热议问题