views:

4402

answers:

8
+4  Q: 

scp via java

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.

+2  A: 

The openssh project lists several Java alternatives, Trilead SSH for Java seems to fit what you're asking for.

Kyle Burton
Trilead seem much more mature than Jsch, but was lacking with sftp and scp support, which is what I was after. Currently, sftp only supported get and put (I need ls and rm also) and scp support was listed as experiental.
Lloyd Meinholz
+3  A: 

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.

Abarax
+6  A: 

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).

Tim Howland
jsch turned out to be the better alternative, but the documentation is horrible. The tip from Abarax to look at ants scp task was very helpful. It's really not clear if the project is still very active. Thanks for the tip.
Lloyd Meinholz
A: 

I use this SFTP API which has SCP called Zehon, it's great, so easy to use with a lot of sample code. Here is the site http://www.zehon.com

A: 

plug: sshj is the only sane choice! See these examples to get started: download, upload.

shikhar
A: 

@Shikahr, can I send file using pscp?

Anonymous
A: 

edtFTPj/PRO supports SCP transfers (as well as SFTP, FTP and FTPS).

Bruce Blackshaw
A: 

For file transfer over SCP/SSH you can try JFileUpload.

http://www.jfileupload.com/products/scp/index.html

It can upload, download and browse remote folders with JDiskExplorer add-on.

fileuploader