简体   繁体   English

使用Putty-Windows中的SSH将ubuntu中的文件复制到Windows

[英]Copy a file in ubuntu to windows using putty - ssh from windows

I Have to copy a .csv file in my ubuntu machine into my windows machine by standing in windows itself. 我必须站在Windows本身中,将ubuntu机器中的.csv文件复制到Windows机器中。 That is I have to do the copying process by running putty or anything like that from windows machine. 那就是我必须通过运行腻子或从Windows计算机上执行类似操作来执行复制过程。 I need it as a command because I have to do it with Java. 我需要它作为命令,因为我必须使用Java。

Call PSCP program from 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");
}

...

Reference 参考

Take a look at JSch . 看看JSch It provides a Java API to do what you want. 它提供了Java API来执行您想要的操作。

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM