public org.apache.commons.net.ftp.FTPFile | parseFTPEntry(java.lang.String entry)Parses a line of a unix FTP server file listing and converts it into a
usable format in the form of an FTPFile instance. If
the file listing line doesn't describe a file, null is
returned, otherwise a FTPFile instance representing the
files in the directory is returned.
FTPFile file = new FTPFile();
file.setRawListing(entry);
if (matches(entry))
{
String usr = group(14);
String grp = group(15);
String filesize = group(16);
String mo = group(17);
String da = group(18);
String yr = group(20);
String hr = group(21);
String min = group(22);
String name = group(23);
file.setType(FTPFile.FILE_TYPE);
file.setUser(usr);
file.setGroup(grp);
try
{
file.setSize(Long.parseLong(filesize));
}
catch (NumberFormatException e)
{
// intentionally do nothing
}
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND,
0);
cal.set(Calendar.MINUTE,
0);
cal.set(Calendar.HOUR_OF_DAY,
0);
try
{
int pos = MONTHS.indexOf(mo);
int month = pos / 4;
if (yr != null)
{
// it's a year
cal.set(Calendar.YEAR,
Integer.parseInt(yr));
}
else
{
// it must be hour/minute or we wouldn't have matched
int year = cal.get(Calendar.YEAR);
// if the month we're reading is greater than now, it must
// be last year
if (cal.get(Calendar.MONTH) < month)
{
year--;
}
cal.set(Calendar.YEAR,
year);
cal.set(Calendar.HOUR_OF_DAY,
Integer.parseInt(hr));
cal.set(Calendar.MINUTE,
Integer.parseInt(min));
}
cal.set(Calendar.MONTH,
month);
cal.set(Calendar.DATE,
Integer.parseInt(da));
file.setTimestamp(cal);
}
catch (NumberFormatException e)
{
// do nothing, date will be uninitialized
}
file.setName(name);
return file;
}
return null;
|