我在写个在FTP上下载文件的程序,指定文件名下载没有问题。但现在 有个需求就是 比如把 08/06/2007 这个时间内的文件全部下载下来。这个就不知道怎么写了。可能是FtpClient类中的某个方法。那个朋友指导一下,给出几行相关代码

解决方案 »

  1.   

    FTPFile[] files = client.listFiles();
    for (int j = 0; j < files.length; j++) {
    Date fileDate = files[j].getTimestamp().getTime();
    // todo...}
      

  2.   

    补充一句:我用的是apache的ftp包
      

  3.   

    up!    apache包  我去看看先了解一下别人还有别的解法吗?
      

  4.   

    我的代码:
    1 这个是 按照文件名取
                TelnetInputStream is = ftpClient.get(filename);
                
                File file_out = new File(localPath + localFileName);
                FileOutputStream os = new FileOutputStream(file_out);
                byte[] bytes = new byte[1024];
                int c;
                while ((c = is.read(bytes)) != -1) {
                    os.write(bytes, 0, c);
                }
    2 这个是把目录都打印出来TelnetInputStream is=ftpClient.list();
           int c;
           while ((c=is.read())!=-1) {
    System.out.print((char) c);}结果显示如下:
    ===========@@@@ login FTP succeed @@@@===========
    total 2144
    -rw-------   1 eprbatch eprbtgrp       3793 Aug 26 2005  .bash_history
    -rw-------   1 eprbatch eprbtgrp        144 Nov 10 2004  .netrc
    -rwxr-x---   1 eprbatch eprbtgrp        441 Mar  9 2006  .profile
    -rw-------   1 eprbatch eprbtgrp       6496 Aug  3 10:34 .sh_history
    -rw-------   1 eprbatch eprbtgrp      14248 Apr 28 21:20 20070429.cron.txt
    -rw-r-----   1 eprbatch eprbtgrp     190728 Jul 11 2006  PR6082.csv
    -rw-r-----   1 eprbatch eprbtgrp      70835 Jul 11 2006  PR6082.sql
    -rw-r-----   1 eprbatch eprbtgrp      22507 Jul 11 2006  PR6082Backup01.csv
    -rw-r-----   1 eprbatch eprbtgrp      21841 Jul 11 2006  PR6082Backup02.csv
    -rw-r-----   1 eprbatch eprbtgrp      21238 Jul 11 2006  PR6082Backup03.csv
    看看大家有什么好的方法处理一下
      

  5.   

    if(sourceFile.isFile()&&,日期<=sourceFile.lastModified() <=日期) {下载 sourceFile
    }