Scp Transfer via Java

scp transfer via java

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

JSch SCP file transfer using exec channel

If the device supports SCP only, do not try to use SFTP, use SCP.

There's an official example for implementing the SCP download using the JSch:

http://www.jcraft.com/jsch/examples/ScpFrom.java.html


Do not get confused by the call of scp in the example code. That's how SCP protocol works. A local (OpenSSH) scp executes the scp on the remote server (with specific non-public arguments, in this case the -f) and then the two instances talk to each other. The example implements the local scp. The arguments used for the remote scp are not the arguments you would use for the local scp.

See also Explanation for SCP protocol implementation in JSch library.

How to transfer folder using scp using pem file.My Program showing no error but showing nothing(my files) on server

In an another approch I have used sh exector directly from my local without connecting to the server first

"echo "+pass+" | "+"sudo -S Worked for me

My full code seems like below :-

String pass = "\"Yourpassword\"";
out.println("echo "+pass+" | "+"sudo -S scp -i "+Pemfilepath+" -r "+targetFolder+" "+"user@xx.xxx.xx.xxx:/var/www/html/projects/demoproject");

Hope it will help you :)



Related Topics



Leave a reply



Submit