Quick Tip: Using Apache Commons Net with IBM i

Something I recently ran into … I use the Apache Commons Net library in some of my java code.

I ran into a problem where, when trying to upload a save file to the host via FTP, I encountered an IOException with the message “501 Unknown extension in database file name”.

Turns out someone had change the FTP server configuration to use *PATH for the NAMEFMT instead of the default *LIB.

This causes FTP output to default to ‘/QSYS.LIB/LIBRARY.LIB/FILE.FILE/MEMBER.MBR’ format instead of ‘FILE.MEMBER’.

As I didn’t want my code to be dependent on the server’s configuration, I had to change the code to set the correct name format.

When using a standard FTP client, you can issue the ‘quot site namefmt 0’ command to change the name format to *LIB (‘quot site namefmt 1’ changes it to *PATH).

So … in my code, after I establish the FTP connection, I have ‘ftpClient.sendSiteCommand(“namefmt 0”);’.  This sets the naming format for the current FTP session.