簡體   English   中英

使用Putty-Windows中的SSH將ubuntu中的文件復制到Windows

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

我必須站在Windows本身中,將ubuntu機器中的.csv文件復制到Windows機器中。 那就是我必須通過運行膩子或從Windows計算機上執行類似操作來執行復制過程。 我需要它作為命令,因為我必須使用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");
}

...

參考

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM