天天看点

远程删除文件 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();

}