File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java.net.UnknownHostException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.net.UnknownHostException" Watch "java.net.UnknownHostException" New topic
Author

java.net.UnknownHostException

Andrew Lowcock
Greenhorn

Joined: Aug 13, 2003
Posts: 8
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.
Many thanks
Andrew
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Well, to restate the obvious, the problem is in how Java's doing name resolution on that Linux machine. If you can ftp to the server from that same machine, using the name of the server host, and Java's failing to open a connection, using the same name, exactly (ie., both using FQDN, or neither using FQDN) then obviously they're using separate lookup mechanisms. Try to make sure they're both using exactly the same name.
The machine may be oddly configured. This is a little reminiscent of a problem I had years ago on a WinNT using a telco-return cable modem; Java and C programs generally disagreed about what the local host's IP address was. Java was clearly using a different resolution mechanism.
Well, sorry, I'm rambling. You wanted ideas for things to poke around in. Have a look in the /etc/hosts file to see if the server host's address is hard-coded there. Also look at /etc/resolv.conf to see what the machine is using for a nameserver(s). Use dig or nslookup to lookup the server both by FQDN and by hostname alone (if this is a LAN situation), and see what you get.


[Jess in Action][AskingGoodQuestions]
Andrew Lowcock
Greenhorn

Joined: Aug 13, 2003
Posts: 8
Thanks,
I probably wasn't 100% clear - but I'm using the IP address, which shouldn't need to be resolved! Therefore I'm thinking more along the lines of security or the context in which the application is running.
Regards
Andrew
Andrew Lowcock
Greenhorn

Joined: Aug 13, 2003
Posts: 8
OK I solved this - I simply needed to .trim() the ip address that I obtained from the database. This extra white space seemed to be ignored on Win2k, but not on Linux....
Cheers
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.net.UnknownHostException
 
Similar Threads
Challenging IP Problem
550 error when using Commons/Net
Socket, java.net.UnknownHostException
FTP site works but I'm unable to connect from Java program. I get java.net.UnknownHostException
Why won't my socket connect?