SshClient client = SshClient.setUpDefaultClient();
client.start();
ClientSession session = client.connect("localhost", port).await().getSession();
session.authPassword("test", "test").await();
ScpClient scp = session.createScpClient();
String data = "0123456789\n";
File root = new File("target/scp");
Utils.deleteRecursive(root);
root.mkdirs();
new File(root, "local").mkdirs();
new File(root, "remote").mkdirs();
assertTrue(root.exists());
writeFile(new File("target/scp/local/out1.txt"), data);
writeFile(new File("target/scp/local/out2.txt"), data);
try {
scp.upload(new String[] { "target/scp/local/out1.txt", "target/scp/local/out2.txt" }, "target/scp/remote/out.txt");
fail("Expected IOException");
} catch (IOException e) {
// Ok
}
writeFile(new File("target/scp/remote/out.txt"), data);
try {
scp.upload(new String[] { "target/scp/local/out1.txt", "target/scp/local/out2.txt" }, "target/scp/remote/out.txt");
fail("Expected IOException");
} catch (IOException e) {
// Ok
}
new File(root, "remote/dir").mkdirs();
scp.upload(new String[] { "target/scp/local/out1.txt", "target/scp/local/out2.txt" }, "target/scp/remote/dir");
assertFileLength(new File("target/scp/remote/dir/out1.txt"), data.length(), 5000);
assertFileLength(new File("target/scp/remote/dir/out2.txt"), data.length(), 5000);
try {
scp.download(new String[] { "target/scp/remote/dir/out1.txt", "target/scp/remote/dir/out2.txt" }, "target/scp/local/out1.txt");
fail("Expected IOException");
} catch (IOException e) {
// Ok
}
try {
scp.download(new String[] { "target/scp/remote/dir/out1.txt", "target/scp/remote/dir/out2.txt" }, "target/scp/local/dir");
fail("Expected IOException");
} catch (IOException e) {
// Ok
}
new File(root, "local/dir").mkdirs();
scp.download(new String[] { "target/scp/remote/dir/out1.txt", "target/scp/remote/dir/out2.txt" }, "target/scp/local/dir");
assertFileLength(new File("target/scp/local/dir/out1.txt"), data.length(), 5000);
assertFileLength(new File("target/scp/local/dir/out2.txt"), data.length(), 5000);
session.close(false);
client.stop();