import java.io.*;
import sun.net.ftp.FtpClient;public class Application1 {public static void main(String args[]) throws Exception {FtpClient fc;String host = "202.145.xxx.xxx";String path = "";
String username = "user";
String password = "name";FtpClient client = new FtpClient(host);
client.login(username, password);
client.binary();
client.cd(".");//这里是设置相对于host主目录的子目录DataInputStream dis =new DataInputStream(client.list());
int readCount;
String s="";
while((s=dis.readLine())!=null) {
if(s.toUpperCase().endsWith(".TXT"))
  System.out.println("Getting: " + s);
}
}
}

解决方案 »

  1.   

    sorry,弄错一个小地方
    DataInputStream dis =new DataInputStream(client.list());
    -->
    DataInputStream dis =new DataInputStream(client.nameList("."));
      

  2.   

    对于jdk1.3以下版本没有nameList方法,做了如下麻烦点的实现:
    import java.io.*;
    import sun.net.ftp.FtpClient;
    import java.util.StringTokenizer;public class Application1 {public static void main(String args[]) throws Exception {FtpClient fc;String host = "172.18.25.211";String path = "";
    String username = "xiruo";
    String password = "xiruojiang";FtpClient client = new FtpClient(host);
    client.login(username, password);
    client.binary();
    client.cd(".");//这里是设置相对于host主目录的子目录//DataInputStream dis =new DataInputStream(client.list());
    BufferedReader dr = new BufferedReader(new InputStreamReader(client.list()));
    int readCount;
    String s="";
    String filename="";
    while((s=dr.readLine())!=null) {
    if((filename=a(s)).toUpperCase().endsWith(".TXT"))
      System.out.println(filename);
    }
    }public static String a(String s) {
      String s1="";
      StringTokenizer st=new StringTokenizer(s," ");
      s1=st.nextToken();
      while(st.hasMoreTokens())
        s=st.nextToken();
      return s1.indexOf("-")==-1?"Folder:"+s:"File:"+s;
    }
    }