This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I've got a big problem. I've have an FTP class that opens a connection to a remote machine, that has been used many times and works well in production. However .... I've recently used the FTP component in another application which I need to show to clients, and I get java.net.UnknownHostException when passing an IP address in as the parameter - this works fine on my Win2k dev machine, and the destination IP is that of another Win2k machine. The code fails on a Linux machine (I can however use the account under which the application is run to manually establish a connection to the FTP server as I would expect) Could anyone please suggest where I could start looking for the problem? I am really at a loss. Apologies if this is the wrong forum. Here is the stack trace. Many thanks (I've posted this to advanced topics also - sorry for the duplication) Exception Trace: java.net.UnknownHostException: rdan at java.net.InetAddress.getAllByName0(InetAddress.java:571) at java.net.InetAddress.getAllByName0(InetAddress.java:540) at java.net.InetAddress.getByName(InetAddress.java:449) at java.net.Socket.<init>(Socket.java:100) at com.companyxxxxx.ftp.FTPControlSocket.<init>(FTPControlSocket.java:78) at com.companyxxxxx.ftp.FTPControlSocket.<init>(FTPControlSocket.java:63) at com.companyxxxxx.ftp.FTPClient.<init>(FTPClient.java:79) at com.companyxxxxx.intranet.candidatexmlimportproofing.servlet.forms.EditCandidateServlet.ftpFiles(EditCandidateServlet.java:547) at com.companyxxxxx.intranet.candidatexmlimportproofing.servlet.forms.EditCandidateServlet.doPost(EditCandidateServlet.java:193)
OK, well, duplication aside, I'm glad you posted this, because the new information is very useful. Look at that stack trace: Java's clearly trying to lookup a host named "rdan"
I looked at the JDK source; these classes haven't changed in a long time so even without knowing what Java version you're using I can see what's going on. The important line is InetAddress.java line 449:
Anyway, you can see that this is being passed a host name, not an IP address, as you assert -- it doesn't start with a number. If you look at the Socket constructor at line 100, you'll see it's just
So without any shadow of a doubt, your code is passing the host name to a Socket constructor, not the dotted-quartet IP address, and the Linux box can't look up the hostname. Check your code! A quick fix, by the way, could be to add the host "rdan" to the /etc/hosts file.