4

I have ftp port as: ftp://173.201.0.1/

I am trying to connect it through following:

String Ftp_Path = "ftp://173.201.0.1/";


    public  List<String>  GetFileList()

    {
         String ftpServerIP = Ftp_Path;
         String ftpUserID = Ftp_UserName;
         String ftpPassword = Ftp_Password;

         FTPFile[] downloadFiles = null;

         StringBuilder result = new StringBuilder();
         FTPClient ftp = new FTPClient();
         List<String> xlsFiles = null;

         try {
            ftp.connect(Ftp_Path);
            ftp.login(ftpUserID, ftpPassword);

            downloadFiles=ftp.listFiles();

            xlsFiles = new ArrayList<String>();
            for(FTPFile i : downloadFiles) {
                if(i.toString().endsWith(".xls")) {
                    xlsFiles.add(i.toString());
                }
            }


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

         return xlsFiles;

    }

But I am getting error on line:

ftp.connect(Ftp_Path);

Following is the error.

java.net.UnknownHostException: ftp://173.201.0.1/
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:92)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:201)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:289)
    at com.amazonaws.mws.samples.ImportRulesPropertyClass.GetFileList(ImportRulesPropertyClass.java:33)
    at com.amazonaws.mws.samples.ManageReportScheduleSample.main(ManageReportScheduleSample.java:74)

Plase help me.

I am new with java.

4
  • 3
    Try only using the Hostname Commented Feb 24, 2014 at 10:48
  • 1
    Have you tried without the protocol prefix? String Ftp_Path = "173.201.0.1"; Commented Feb 24, 2014 at 10:48
  • 1
    Use 173.201.0.1 instead of ftp://173.201.0.1/ As in example commons.apache.org/proper/commons-net/apidocs/org/apache/… Commented Feb 24, 2014 at 10:49
  • are you behind proxy? do you have INTERNET permission added in your manifest? Commented Feb 24, 2014 at 10:49

1 Answer 1

10

You just need to specify the IP.The FTPClient makes a ftp request.It is not similar to http request.Just change

String Ftp_Path = "ftp://173.201.0.1/";

to 

String Ftp_Path = "173.201.0.1";

Also check whether the ftp port is up and accessible through telnet

Sign up to request clarification or add additional context in comments.

1 Comment

bro, request u to help on this also stackoverflow.com/questions/21986121/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.