I use the Ganymed library to access ingress.
Then add the Ganymed-ssh2-build2 library to our Java application.
Suppose I have put a folder test under the/home/chenshu directory of UBuntu Server 9.04 of 192.168.0.110. The test folder corresponds to the test Java class package name. We use javac on this machine. /test/Main. after java compilation, run the Java program on another machine, the program completes the remote call function by calling the class of the newly created Ganymed-ssh2-build2 Library:
- package javaapplication3;
-
- import ch.ethz.ssh2.Connection;
- import ch.ethz.ssh2.ConnectionInfo;
- import ch.ethz.ssh2.Session;
- /**
- *
- * @author chenshu
- */
- public class Main {
- public static void main(String[] args) {
- try {
- Connection con = new Connection("192.168.0.110");
- ConnectionInfo info = con.connect();
- boolean result = con.authenticateWithPassword("chenshu", "770328");
- Session session = con.openSession();
- session.execCommand("java test.Main");
- } catch (Exception ex) {
- System.out.println(ex.getLocalizedMessage());
- }
- }
- }
Now we can see that there is another test.txt on the server, which is the file generated after the test. Main class is run. You can release a Java test program. The test program code is irrelevant.
Done!