Java 从windows使用putty-ssh将ubuntu中的文件复制到windows
我必须在我的ubuntu机器上复制一个.csv文件到我的windows机器上,只需站在windows本身。也就是说,我必须通过运行putty或类似于windows机器的任何东西来完成复制过程。我需要它作为一个命令,因为我必须用Java来做。它提供了一个JavaAPI来做你想做的事情 看一看。它提供了一个JavaAPI来做你想做的事情 从Java调用程序:Java 从windows使用putty-ssh将ubuntu中的文件复制到windows,java,ubuntu,ssh,putty,file-copying,Java,Ubuntu,Ssh,Putty,File Copying,我必须在我的ubuntu机器上复制一个.csv文件到我的windows机器上,只需站在windows本身。也就是说,我必须通过运行putty或类似于windows机器的任何东西来完成复制过程。我需要它作为一个命令,因为我必须用Java来做。它提供了一个JavaAPI来做你想做的事情 看一看。它提供了一个JavaAPI来做你想做的事情 从Java调用程序: String[] command = { "pscp", "-q", // quiet, don't show statist
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");
}
...
参考
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");
}
...
参考
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");
}
试试看:
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");
}
你能在回答中也提到参数吗。。我的意思是-2-p22等等。我在哪里提到我必须从Ubuntu复制的csv文件。我在哪里提到csv文件的源(在Ubuntu中)和目标(在windows中)。你能在回答中提到参数吗。。我的意思是-2-p22等。我在哪里提到我必须从Ubuntu复制的csv文件。我在哪里提到csv文件的源(在Ubuntu中)和目标(在windows中)。你能在回答中提到参数的细节吗?我在哪里提到源(在Ubuntu中)和目标(在windows中)是csv文件。非常感谢Alex。这对我帮助很大。。回答的好方法:)你能在回答中提到参数的细节吗..我在哪里提到csv文件的源(在ubuntu中)和目标(在windows中)。非常感谢Alex。这对我帮助很大。。回答的好方法:)