Question

i used CrossFTP to create FTP Server alt text

when i connected using firefox it works well.

but when using Apache commons it throws an Exception

import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;

public class FtpConnectDemo {
  public static void main(String[] args) throws SocketException, IOException {
    FTPClient client = new FTPClient();
    client.connect("ftp://192.168.1.150");
    boolean login = client.login("ehab01", "CD7IZW0O");

    if (login) {
      System.out.println("Login success...");
      boolean logout = client.logout();
      if (logout) {
        System.out.println("Logout from FTP server...");
      }
    } else {
      System.out.println("Login fail...");
    }
    client.disconnect();
  }
}

    Exception in thread "main" java.net.UnknownHostException: ftp://192.168.1.150
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
        at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
        at java.net.InetAddress.getAllByName(InetAddress.java:1083)
        at java.net.InetAddress.getAllByName(InetAddress.java:1019)
        at java.net.InetAddress.getByName(InetAddress.java:969)
        at org.apache.commons.net.SocketClient.connect(SocketClient.java:184)
        at org.apache.commons.net.SocketClient.connect(SocketClient.java:273)
        at com.ftp.FtpConnectDemo.main(FtpConnectDemo.java:19)
Was it helpful?

Solution

Your hostname argument should be just 192.168.1.150, not ftp://192.168.1.150.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top