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 libraries. None of these solutions seem to have an easy answer.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I ended up using Jsch- it was pretty straightforward, and seemed to scale up pretty well (I was grabbing a few thousand files every few minutes).
Take a look here
That is the source code for Ants' SCP task. The code in the "execute" method is where the nuts and bolts of it are. This should give you a fair idea of what is required. It uses JSch i believe.
Alternatively you could also directly execute this Ant task from your java code.
-: Refining Fernando's answer a little, if you use Maven for dependency management :-
pom.xml:
Add this dependency in your project. Latest version can be found here.
Java code:
The openssh project lists several Java alternatives, Trilead SSH for Java seems to fit what you're asking for.
Like some here, I ended up writing a wrapper around the JSch library.
It's called way-secshell and it is hosted on GitHub:
https://github.com/objectos/way-secshell
I wrapped Jsch with some utility methods to make it a bit friendlier and called it
Jscp
Available here: https://github.com/willwarren/jscp
SCP utility to tar a folder, zip it, and scp it somewhere, then unzip it.
Usage:
Also includes useful classes - Scp and Exec, and a TarAndGzip, which work in pretty much the same way.