URLConnection FTP list files

后端 未结 3 1300
抹茶落季
抹茶落季 2020-12-11 04:09
URL url =  new URL(\"ftp://user:pass@ftp.example.com/thefolder/\");
URLConnection connection = url.openConnection();
...
// List files in folder...

3条回答
  •  温柔的废话
    2020-12-11 04:35

    You could use Apache commons FTPClient

    This would allow you to call listFiles with...

    public static void main(String[] args) throws IOException {
            FTPClient client = new FTPClient();
            client.connect("c64.rulez.org");
            client.enterLocalPassiveMode();
            client.login("anonymous", "");
            FTPFile[] files = client.listFiles("/pub");
            for (FTPFile file : files) {
                System.out.println(file.getName());
            }
    

提交回复
热议问题