apache.commons.net ParserInitializationException July 14, 2005
Posted by javafoo in apache commons, javanotes.trackback
We use the jakarta/apache (don’t know what they call it these days) commons net jar as our ftp client and this seems to be failing with a TANDEM ftp box. Looks like someone else was running into the same error at about the same time.
This is the error I was running into:org.apache.commons.net.ftp.parser.ParserInitializationException:
Error initializing parser at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.
createFileEntryParser(DefaultFTPFileEntryParserFactory.java:115) at org.apache.commons.net.ftp.FTPClient.
initiateListParsing(FTPClient.java:2306) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2055) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2106) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2146)
After taking a look at the commons code, here’s what I figured out, the TANDEM box was returning
an empty string on a FTP SYST command. Our good people at commons don’t handle a null, assuming
the FTPClient.getSystemName() always returns something. So here’s my hack to get around it.
if(null == ftpClient.getSystemName()) {
//use parserKey,pathName method signature
ftpFileArray = ftpClient.listFiles(“UNIX”,(String)null);
} else {
ftpFileArray = ftpClient.listFiles();
}
Informative blog. I have a xml sql server blog.
HI,
I tried your fix in my code:
FTPFile[] files = null;
if(null == http://ftp.getSystemName()) {
/use parserKey,pathName method ture
files = http://ftp.listFiles(“UNIX”,(String)null);
} else {
files = http://ftp.listFiles();
}
but i still get failure:
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException
at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createUnixFTPEntryParser(DefaultFTPFileEntryParserFactory.java:169)
at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createFileEntryParser(DefaultFTPFileEntryParserFactory.java:94)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2345)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2090)
at com.ericsson.snmp.ftp.main(ftp.java:143)
Press any key to continue . . .
any idea why?
goks your error seems to be different. You might be using a different commons net version. Also not sure what OS your ftp box is using. For me it was a HP Tandem, which was close to generic UNIX, thats the reason I used “UNIX”, there. You might want to see what OS your ftp server is using and use the appropriate string.–>
download oro.jar from apache org and import
org/apache/oro/text/regex/MalformedPatternException this should solve
I am getting the same problem, for more that two days I have been looking around but all the solutions I find do not work. I have added a FTPClientConfig with a new UnixFTPEntryParser but it does not even get call.
I am tired of wasting my time with this API.
no idea why, but adding the oro jar to my classpath did fix it.
If you can explain why this worked, that would be so cool.
thanks!
this works for me.
private FTPFile[] readFile() throws IOException {
client.changeWorkingDirectory(“/home/thomasmodeneis”);
client.setFileType(FTPClient.ASCII_FILE_TYPE);
if(null == client.getSystemName()) {
//use parserKey,pathName method signature
return client.listFiles(“UNIX”,(String)null);
} else {
return client.listFiles();
}
}
thank you.
Is anyone tried to connect to OpenBSD ftp server through ant?
I am getting the same ParserInitializationException. I tried everything that suggested here in other sites. I have the fixed commons_net.jar. nothing works for me.
Please advise.
Thank you.