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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.net.ftp;
import java.io.Serializable;
import java.util.Calendar;
/***
* The FTPFile class is used to represent information about files stored
* on an FTP server. Because there is no standard representation for
* file information on FTP servers, it may not always be possible to
* extract all the information that can be represented by FTPFile, or
* it may even be possible to extract more information. In cases where
* more information can be extracted, you will want to subclass FTPFile
* and implement your own {@link org.apache.commons.net.ftp.FTPFileListParser}
* to extract the information.
* However, most FTP servers return file information in a format that
* can be completely parsed by
* {@link org.apache.commons.net.ftp.DefaultFTPFileListParser}
* and stored in FTPFile.
* <p>
* <p>
* @author Daniel F. Savarese
* @see FTPFileListParser
* @see DefaultFTPFileListParser
* @see FTPClient#listFiles
***/
public class FTPFile implements Serializable
{
/** A constant indicating an FTPFile is a file. ***/
public static final int FILE_TYPE = 0;
/** A constant indicating an FTPFile is a directory. ***/
public static final int DIRECTORY_TYPE = 1;
/** A constant indicating an FTPFile is a symbolic link. ***/
public static final int SYMBOLIC_LINK_TYPE = 2;
/** A constant indicating an FTPFile is of unknown type. ***/
public static final int UNKNOWN_TYPE = 3;
/** A constant indicating user access permissions. ***/
public static final int USER_ACCESS = 0;
/** A constant indicating group access permissions. ***/
public static final int GROUP_ACCESS = 1;
/** A constant indicating world access permissions. ***/
public static final int WORLD_ACCESS = 2;
/** A constant indicating file/directory read permission. ***/
public static final int READ_PERMISSION = 0;
/** A constant indicating file/directory write permission. ***/
public static final int WRITE_PERMISSION = 1;
/**
* A constant indicating file execute permission or directory listing
* permission.
***/
public static final int EXECUTE_PERMISSION = 2;
int _type, _hardLinkCount;
long _size;
String _rawListing, _user, _group, _name, _link;
Calendar _date;
boolean[] _permissions[];
/*** Creates an empty FTPFile. ***/
public FTPFile()
{
_permissions = new boolean[3][3];
_rawListing = null;
_type = UNKNOWN_TYPE;
_hardLinkCount = 0;
_size = 0;
_user = null;
_group = null;
_date = null;
_name = null;
}
/***
* Set the original FTP server raw listing from which the FTPFile was
* created.
* <p>
* @param rawListing The raw FTP server listing.
***/
public void setRawListing(String rawListing)
{
_rawListing = rawListing;
}
/***
* Get the original FTP server raw listing used to initialize the FTPFile.
* <p>
* @return The original FTP server raw listing used to initialize the
* FTPFile.
***/
public String getRawListing()
{
return _rawListing;
}
/***
* Determine if the file is a directory.
* <p>
* @return True if the file is of type <code>DIRECTORY_TYPE</code>, false if
* not.
***/
public boolean isDirectory()
{
return (_type == DIRECTORY_TYPE);
}
/***
* Determine if the file is a regular file.
* <p>
* @return True if the file is of type <code>FILE_TYPE</code>, false if
* not.
***/
public boolean isFile()
{
return (_type == FILE_TYPE);
}
/***
* Determine if the file is a symbolic link.
* <p>
* @return True if the file is of type <code>UNKNOWN_TYPE</code>, false if
* not.
***/
public boolean isSymbolicLink()
{
return (_type == SYMBOLIC_LINK_TYPE);
}
/***
* Determine if the type of the file is unknown.
* <p>
* @return True if the file is of type <code>UNKNOWN_TYPE</code>, false if
* not.
***/
public boolean isUnknown()
{
return (_type == UNKNOWN_TYPE);
}
/***
* Set the type of the file (<code>DIRECTORY_TYPE</code>,
* <code>FILE_TYPE</code>, etc.).
* <p>
* @param type The integer code representing the type of the file.
***/
public void setType(int type)
{
_type = type;
}
/***
* Return the type of the file (one of the <code>_TYPE</code> constants),
* e.g., if it is a directory, a regular file, or a symbolic link.
* <p>
* @return The type of the file.
***/
public int getType()
{
return _type;
}
/***
* Set the name of the file.
* <p>
* @param name The name of the file.
***/
public void setName(String name)
{
_name = name;
}
/***
* Return the name of the file.
* <p>
* @return The name of the file.
***/
public String getName()
{
return _name;
}
/**
* Set the file size in bytes.
* @param size The file size in bytes.
*/
public void setSize(long size)
{
_size = size;
}
/***
* Return the file size in bytes.
* <p>
* @return The file size in bytes.
***/
public long getSize()
{
return _size;
}
/***
* Set the number of hard links to this file. This is not to be
* confused with symbolic links.
* <p>
* @param links The number of hard links to this file.
***/
public void setHardLinkCount(int links)
{
_hardLinkCount = links;
}
/***
* Return the number of hard links to this file. This is not to be
* confused with symbolic links.
* <p>
* @return The number of hard links to this file.
***/
public int getHardLinkCount()
{
return _hardLinkCount;
}
/***
* Set the name of the group owning the file. This may be
* a string representation of the group number.
* <p>
* @param group The name of the group owning the file.
***/
public void setGroup(String group)
{
_group = group;
}
/***
* Returns the name of the group owning the file. Sometimes this will be
* a string representation of the group number.
* <p>
* @return The name of the group owning the file.
***/
public String getGroup()
{
return _group;
}
/***
* Set the name of the user owning the file. This may be
* a string representation of the user number;
* <p>
* @param user The name of the user owning the file.
***/
public void setUser(String user)
{
_user = user;
}
/***
* Returns the name of the user owning the file. Sometimes this will be
* a string representation of the user number.
* <p>
* @return The name of the user owning the file.
***/
public String getUser()
{
return _user;
}
/***
* If the FTPFile is a symbolic link, use this method to set the name of the
* file being pointed to by the symbolic link.
* <p>
* @param link The file pointed to by the symbolic link.
***/
public void setLink(String link)
{
_link = link;
}
/***
* If the FTPFile is a symbolic link, this method returns the name of the
* file being pointed to by the symbolic link. Otherwise it returns null.
* <p>
* @return The file pointed to by the symbolic link (null if the FTPFile
* is not a symbolic link).
***/
public String getLink()
{
return _link;
}
/***
* Set the file timestamp. This usually the last modification time.
* The parameter is not cloned, so do not alter its value after calling
* this method.
* <p>
* @param date A Calendar instance representing the file timestamp.
***/
public void setTimestamp(Calendar date)
{
_date = date;
}
/***
* Returns the file timestamp. This usually the last modification time.
* <p>
* @return A Calendar instance representing the file timestamp.
***/
public Calendar getTimestamp()
{
return _date;
}
/***
* Set if the given access group (one of the <code> _ACCESS </code>
* constants) has the given access permission (one of the
* <code> _PERMISSION </code> constants) to the file.
* <p>
* @param access The access group (one of the <code> _ACCESS </code>
* constants)
* @param permission The access permission (one of the
* <code> _PERMISSION </code> constants)
* @param value True if permission is allowed, false if not.
***/
public void setPermission(int access, int permission, boolean value)
{
_permissions[access][permission] = value;
}
/***
* Determines if the given access group (one of the <code> _ACCESS </code>
* constants) has the given access permission (one of the
* <code> _PERMISSION </code> constants) to the file.
* <p>
* @param access The access group (one of the <code> _ACCESS </code>
* constants)
* @param permission The access permission (one of the
* <code> _PERMISSION </code> constants)
***/
public boolean hasPermission(int access, int permission)
{
return _permissions[access][permission];
}
/***
* Returns a string representation of the FTPFile information. This
* will be the raw FTP server listing that was used to initialize the
* FTPFile instance.
* <p>
* @return A string representation of the FTPFile information.
***/
@Override
public String toString()
{
return _rawListing;
}
}
|