Search code examples
javasshjschsshj

SSH with Command and File in Java


I'd like to run SSH within Java but I haven't figured out how to run an SSH statement that includes a command and file. The command for example in a standard terminal:

ssh user@host 'upload' < myfile.txt

Hopefully via a Java library, not some type of Runtime.exec()


Solution

  • Try: http://www.jcraft.com/jsch/

    Here you have the example you need:
    http://www.jcraft.com/jsch/examples/ScpTo.java.html