Meaningless Drivel is fun!
The moose likes I/O and Streams and the fly likes Socket, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Socket, " Watch "Socket, " New topic


Andrew Lowcock

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 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: rdan
at com.companyxxxxx.ftp.FTPControlSocket.<init>(
at com.companyxxxxx.ftp.FTPControlSocket.<init>(
at com.companyxxxxx.ftp.FTPClient.<init>(
at com.companyxxxxx.intranet.candidatexmlimportproofing.servlet.forms.EditCandidateServlet.ftpFiles(
at com.companyxxxxx.intranet.candidatexmlimportproofing.servlet.forms.EditCandidateServlet.doPost(
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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

[Jess in Action][AskingGoodQuestions]
Andrew Lowcock

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....
I agree. Here's the link:
subject: Socket,
It's not a secret anymore!