AFtpRemoteFile.java
2.42 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.sitech.util.upload;
import java.io.IOException;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
public class AFtpRemoteFile {
protected FTPClient ftpClient = null;
protected FTPFile ftpFile = null;
protected String currDir = null;
public AFtpRemoteFile(FTPFile rfile, FTPClient ftpClient, String currDir)
throws IOException {
this.ftpClient = ftpClient;
this.ftpFile = rfile;
this.currDir = currDir;
}
/**
* 获得远程文件的文件大小
*/
public long getSize() {
return ftpFile.getSize();
}
public String getPermissons(){
return split(ftpFile.getRawListing(),0);
}
/**
* 获得远程文件的文件名称
*/
public String getFileName() {
return ftpFile.getName();
}
/**
* 判断当前的元素是否为目录
*/
public boolean isDirectory() {
return ftpFile.isDirectory();
}
/**
* 判断当前的元素是否为文件
*/
public boolean isFile() {
return ftpFile.isFile();
}
/**
* 获得远程文件的创建者
*/
public String getOwner() {
return ftpFile.getUser();
}
/**
* 获得远程文件的最后一次修改时间。
* @return
*/
public Date getModifyDate() {
return ftpFile.getTimestamp().getTime();
}
/**
* 修改远程文件/目录的名称
* 此方法能够修改当前工作路径‘pwd()’下的文件/目录的名称
* 为新名称‘newName’,注意参数‘newName’只是元素名称,不得包
* 含路径。
* @throws IOException
*/
public boolean renameTo(String newName) throws IOException {
return ftpClient.rename(
currDir.concat(getFileName()), newName);
}
/**
* 删除远程文件。
* 此方法删除目录时会报出‘Delete operation failed.’
* 可能没有执行此操作的权限。
*
* 注意:该方法不能删除一个非空目录。
* @throws IOException
*/
public boolean remove() throws IOException {
return ftpClient.deleteFile(
currDir.concat(getFileName()));
}
public void release() {
ftpClient = null;
ftpFile = null;
currDir = null;
}
public String split(String str, int pos) {
StringTokenizer st = new StringTokenizer(str);
Vector<String> values = new Vector<String>();
while (st.hasMoreTokens()) {
values.add(st.nextToken());
}
if (pos >= 0 && pos < values.size()) {
return values.get(pos);
}
return "";
}
}