Wednesday, January 23, 2008

Jakarta's FTPClient and localhost

I was asked to build a web application that would receive an input file through HTTP Upload, work on the file, and then upload a resulting file on an FTP server.

In order to test the application, I set up an FTP server (filezilla) on my development machine.

Everything was working fine on the dev machine. I then changed my properties file to switch to the production FTP server. At that point, the FTP part didn't work : it seemed that the login credentials were wrong. I checked the credentials with a command prompt FTP session, and it was working fine.

After pulling my hair a little bit, I realized I had a bug in the program on the line where I used FTPClient's connect method : instead of using the FTP host specified in the properties file, I was using NULL. This translated in the program connecting to localhost, which explains why the program worked with an FTP server on my development machine, and not with a remote FTP server.

So, with Jakarta's FTPClient class, a null host means localhost when using the connect method.

No comments:

Post a Comment