“How to copy a file using Jsch?” was the question first in place. As using Jsch is complicated and error-prone and also works very low-level, you need to program several lines to get a simple scp working.
So, how do I implement a scp (or even sftp) with as few lines of code as possible in Java and not violate the DRY principle?
You can use the libraries used by the Ant scp task:
I did this with following jars in my classpath:
This example can easily be extended to upload files or use SFTP instead.