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

原创
2012/03/08 12:03
阅读数 5.5W
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();



展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部