1

I have some code Running on Tomcat that connects to and FTP to download some files. The FTP works fine on the server where the Tomcat is running when I connect via command line. My code also works when running on my PC. However, when I run it on the server's Tomcat, I get the following Exception:

java.net.UnknownHostException: 192.168.1.9

How is that even possible? It's an IP Address, not a hostname. The full stack trace below:

java.net.UnknownHostException: 192.168.1.9
    at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
    at java.net.InetAddress.getAllByName(InetAddress.java:1084)
    at java.net.InetAddress.getAllByName(InetAddress.java:1020)
    at java.net.InetAddress.getByName(InetAddress.java:970)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:203)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:296)

I have no idea how to fix this. Any ideas?

This is the code that makes it fail like this:

    final FTPClient ftp = new FTPClient();
    ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    int reply;
    ftp.connect("192.168.1.9");

It fails on that last line

manugarciac
  • 185
  • 1
  • 12

1 Answers1

5

Now I feel stupid. The problem was that the IP had a white space because it got there via a properties file that had an extra white space on that param. So sorry everyone.

manugarciac
  • 185
  • 1
  • 12