i want to ssh a server and run some commands ...
i tried that code but i prompt for password is there any api for ssh how can i do that
import java.util.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.lang.*;
import java.io.IOException;
import java.net.SocketException;
public class MyClass
{
public static void main( String[] args )
{
File wd = new File("/bin");
System.out.println(wd);
Process proc = null;
Process proc2 = null;
try {
proc = Runtime.getRuntime().exec("/bin/bash", null, wd);
}
catch (IOException e) {
e.printStackTrace();
}
if (proc != null) {
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
out.println("cd /");
out.println("ssh root@122.20.19.10");
out.println("cd /");
out.println("ls");
out.println("pwd");
out.println("exit");
try {
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
proc.waitFor();
in.close();
out.close();
proc.destroy();
}
catch (Exception e) {
e.printStackTrace();
}
}
}//end of main mehtod
}//END OF CLASS
thanks