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
Creating an Animated 4X4 Grid in Java
"Not Allowed to Load Local Resource: File:///C:....Jpg" Java Ee Tomcat
Why Is This Java Code in Curly Braces ({}) Outside of a Method
Java Threads and Number of Cores
Pass Array to Oracle Procedure
Java Raw Type and Generics Interaction
Why Is My Jlabel Not Showing Up
How to Declare a 2D String Arraylist
Reflections - Java 8 - Invalid Constant Type
How to Capture Video Using Jmf, But Without Installing Jmf
Closing Bufferedreader and System.In
Remove Last Character of a Stringbuilder
Why Does Intellij Give Me "Package Doesn't Exist" Error
JPA - Returning an Auto Generated Id After Persist()
Compile Error: Package Javax.Servlet Does Not Exist
Is There a Way in Java to Convert an Integer to Its Ordinal Name