天天看點

遠端删除檔案 java_如何用java代碼删除遠端伺服器上的檔案,通過ip 位址

public void testSsh() {

String hostname = "192.168.0.1";

String username = "root";

String password = "password";

Connection conn = new Connection(hostname);

conn.connect();

System.out.println("connect ok");

boolean isAuthenticated = conn.authenticateWithPassword(username,password);

if (isAuthenticated == false)

throw new IOException("Authentication failed.");

Session sess = conn.openSession();

sess.execCommand("rm -rf 目錄");

System.out.println("Here is some information about the remote host:");

sess.close();

conn.close();

}