Reputation: 8498
I Have to copy a .csv file in my ubuntu machine into my windows machine by standing in windows itself. That is I have to do the copying process by running putty or anything like that from windows machine. I need it as a command because I have to do it with Java.
Upvotes: 1
Views: 1045
Reputation: 43053
Call PSCP program from Java:
String[] command = {
"pscp",
"-q", // quiet, don't show statistics
"-pw", // passw login with specified password
"yourP4ssw0rd", // the user password
"username@yourhost:file.csv",
"c:\\the\\destination\\of\\your\\file.csv"
};
// command == pscp -q -pw yourP4ssw0rd username@yourhost:file.csv c:\\the\\destination\\of\\your\\file.csv
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
sb.append(line + "\n");
}
...
Upvotes: 2
Reputation: 101
try that:
Process p = Runtime.getRuntime().exec("putty -ssh -2 -P 22 USERNAME@SERVER_ADDR -pw PASS -m command.txt");
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
sb.append(line + "\n");
}
Upvotes: 1
Reputation: 2579
Take a look at JSch. It provides a Java API to do what you want.
Upvotes: 1