问题概要:你懂得 ...
原因: common-net 缺少对 V900R012 类型系统的支持
方案:
1) FTPClientConfig.java
增加字段
public static final String SYST_V900R012 = "V900R012";
2) DefaultFTPFileEntryParserFactory
修改方法 private FTPFileEntryParser createFileEntryParser(String key, FTPClientConfig config) , 增加
else if (ukey.indexOf("V900R012") >= 0)
{
parser = new V900R012FTPEntryParser();
}
3) 新建 V900R012FTPEntryParser.java
package org.apache.commons.net.ftp.parser;
import java.text.ParseException;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
public class V900R012FTPEntryParser extends ConfigurableFTPFileEntryParserImpl
{
private static final String DEFAULT_DATE_FORMAT = "MM-dd-yy HH:mm";
private static final String REGEX = "(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+/?)\\s*";
public V900R012FTPEntryParser()
{
this(null);
}
public V900R012FTPEntryParser(FTPClientConfig config) {
super("(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+/?)\\s*");
configure(config);
}
public FTPFile parseFTPEntry(String entry) {
FTPFile file = new FTPFile();
file.setRawListing(entry);
if (matches(entry)) {
String datestr = group(1) + " " + group(2);
String dirFlag = group(3);
String filesize = "";
int type;
if (dirFlag.contains("<DIR>")) {
type = 1;
filesize = "0";
} else {
type = 0;
filesize = group(3);
}
String name = group(4);
try {
file.setTimestamp(super.parseTimestamp(datestr));
} catch (ParseException e) {
return null;
}
file.setType(type);
try {
file.setSize(Long.parseLong(filesize));
}
catch (NumberFormatException e) {
}
if (name.endsWith("/")) {
name = name.substring(0, name.length() - 1);
}
int pos = name.lastIndexOf('/');
if (pos > -1) {
name = name.substring(pos + 1);
}
file.setName(name);
return file;
}
return null;
}
protected FTPClientConfig getDefaultConfiguration() {
return new FTPClientConfig("OS/400", "MM-dd-yy HH:mm", null, null, null, null);
}
}