jump to navigation

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();
}

Comments»

1. Steve Austin - October 2, 2005

Informative blog. I have a xml sql server blog.

2. goks - February 19, 2006

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?

3. Java Foo - February 24, 2006

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.–>

4. Mortoza shoeb - April 3, 2007

download oro.jar from apache org and import
org/apache/oro/text/regex/MalformedPatternException this should solve

5. fdm - January 15, 2008

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.

6. Ryan J Sullivan - March 3, 2008

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!

7. Thomas - October 29, 2008

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.

Shanthi - September 4, 2009

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.

8. p90x - May 5, 2012

Strive to preserve your health; and in this you will better succeed in proportion as you keep clear of the physicians, for their drugs are a kind of alchemy concerning which there are no fewer books than there are medicines….

Frugality without creativity is deprivation….

9. www.youngmoneyhq.com - March 5, 2014

If you plan to be a book heroine, this means that you must eat all the time, except when
you’re not eating, and then you should be thinking about eating.
For more information on my Workshops, Writing Mastermind
Groups and private coaching, please go to my website listed below and feel free to call me any time.
Wouldn’t it be nice if we could take a magic pill and have a perfect relationship.

10. http://vbridge.twgrid.org/ - July 8, 2014

Every weekend i used to pay a visit this web site, because i want enjoyment, as this this web page conations actually pleasant funny material too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: