質問

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.

役に立ちましたか?

解決

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");
}

...

Reference

他のヒント

Take a look at JSch. It provides a Java API to do what you want.

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");
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top