【问题标题】:Apache Java FTPclient order by timestamp [duplicate]Apache Java FTPclient按时间戳排序[重复]
【发布时间】:2018-03-28 15:51:16
【问题描述】:

是否可以使用 Apache ftp 客户端并按时间戳列出目录内容? 我在做:

mFtpClient.listNames("-t .");

但返回一个空列表。

编辑:我正在使用 Filezilla Server。

【问题讨论】:

    标签: java apache ftp ftp-client


    【解决方案1】:

    我是这样解决的:

    public class CustomFTPClient extends FTPClient{
    
        public String[] listNamesOrdered(String pathname) throws IOException
        {
            if(pathname == null) pathname = "";
            StringBuilder sb = new StringBuilder(pathname.length() + 3);
            sb.append("-t -A1 ");
            sb.append(pathname);
            pathname = sb.toString();
    
            Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));
    
            if (socket == null) {
                return null;
            }
    
            BufferedReader reader =
                    new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));
    
            ArrayList<String> results = new ArrayList<String>();
            String line;
            while ((line = reader.readLine()) != null) {
                results.add(line);
            }
    
            reader.close();
            socket.close();
    
            if (completePendingCommand())
            {
                String[] names = new String[ results.size() ];
                return results.toArray(names);
            }
    
            return null;
        }
    
    }
    

    我复制了 listNames 方法,并使用了带有 -t 参数的 LIST 命令。

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      • 2019-09-06
      相关资源
      最近更新 更多