我必须通过站在Windows本身中,将Ubuntu机器中的.CSV文件复制到Windows机器中。那就是我必须通过运行Windows Machine中的腻子或类似的内容来进行复制过程。我需要它作为命令,因为我必须使用java进行。
java呼叫PSCP程序:
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");
}
...
参考
- PSCP手册
- 下载PSCP
看一下JSCH。它提供了Java API来完成您想要的事情。
尝试:
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");
}