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());
new File("target/scp/local/dir").mkdirs();
long lastMod = new File("target/scp/local/dir").lastModified() - TimeUnit.DAYS.toMillis(1);
writeFile(new File("target/scp/local/out1.txt"), data);
writeFile(new File("target/scp/local/dir/out2.txt"), data);
new File("target/scp/local/out1.txt").setLastModified(lastMod);
new File("target/scp/local/out1.txt").setExecutable(true, true);
new File("target/scp/local/out1.txt").setWritable(false, false);
new File("target/scp/local/dir/out2.txt").setLastModified(lastMod);
scp.upload("target/scp/local/*", "target/scp/remote/", ScpClient.Option.Recursive, ScpClient.Option.PreserveAttributes);
assertFileLength(new File("target/scp/remote/out1.txt"), data.length(), 5000);
assertEquals(lastMod, new File("target/scp/remote/out1.txt").lastModified());
assertFileLength(new File("target/scp/remote/dir/out2.txt"), data.length(), 5000);
assertEquals(lastMod, new File("target/scp/remote/dir/out2.txt").lastModified());
Utils.deleteRecursive(new File("target/scp/local"));
new File("target/scp/local").mkdirs();
scp.download("target/scp/remote/*", "target/scp/local", ScpClient.Option.Recursive, ScpClient.Option.PreserveAttributes);
assertFileLength(new File("target/scp/local/out1.txt"), data.length(), 5000);
assertEquals(lastMod, new File("target/scp/local/out1.txt").lastModified());
assertFileLength(new File("target/scp/local/dir/out2.txt"), data.length(), 5000);
assertEquals(lastMod, new File("target/scp/local/dir/out2.txt").lastModified());