利用ftp4j删除WAS上的heapdump和javacore文件

import it.sauronsoftware.ftp4j.FTPClient;

import java.io.File;

void init(String server, String user, String passwd, String path) {
	FTPClient client = new FTPClient();
	try {
		String[] ret = client.connect(server);
		for (String r : ret) {
			System.out.println("out " + r);
		}
		client.login(user, passwd);

		client.changeDirectory(path);
		
		if (!new File(server).isDirectory()) {
			System.out.println("making directory " + server);
			new File(server).mkdir();
		}
		String[] fileNames = client.listNames();
		for (String file : fileNames) {
			if (file.indexOf("heapdump") != -1
					|| file.indexOf("javacore") != -1) {
				System.out.println("download file " + file);
				client.download(file, new File(server + "/" + file));
				client.deleteFile(file);
				System.out.println("file " + file + " deleted.");
			}
		}
		//			client.deleteFile("test.txt");
		//
		client.logout();
		client.disconnect(true);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

void main() {
	String server = "server";
	String user = "root";
	String passwd = "password";
	String path = "/usr/WebSphere/AppServer/logs/dhwas1";
	if (bsh.args.length > 0) {
		server = bsh.args[0];
		user = bsh.args[1];
		passwd = bsh.args[2];
		path = bsh.args[3];
	} else {
		System.out
				.println("usage: java -cp bin;ftp4j-1.7.jar;bsh-2.0b4.jar bsh.Interpreter cleanLog.sh serverName root password /usr/WebSphere/AppServer/logs/dhwas1");
	}
	init(server, user, passwd, path);
}

main();



你可能感兴趣的:(利用ftp4j删除WAS上的heapdump和javacore文件)