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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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();