/**
                     * 获取目录下所有文件
                     *  
                     * @param dir
                     *            目录
                     * @return
                     * @throws Exception
                     */  
                    public String[] listNames(String dir) throws Exception {  
                        FTPClient client = null;  
                        try {  
                            client = getClient();  
                            client.changeDirectory(dir);  
                            String[] values = client.listNames();  
                            if (values != null) {  
                                // 将文件排序(忽略大小写)  
                                Arrays.sort(values, new Comparator<String>(){  
                                    public int compare(String val1, String val2) {  
                                        return val1.compareToIgnoreCase(val2);  
                                    }  
                                });  
                            }  
                            return values;  
                        } catch(FTPException fe) {  
                            // 忽略文件夹不存在的情况  
                            String mark = "code=550";  
                            if (fe.toString().indexOf(mark) == -1) {  
                                throw fe;  
                            }  
                        } finally {  
                            logout(client);  
                        }  
                        return new String[0];  
                    }  
                }
五、测试
    1.在项目中创建test目录
        /test
    2.在test目录下创建包
        包名:cn.jbit.test
    3.在包下创建测试类
        测试类名:FtpUtilsTest.java
        测试类内容:
            public class FtpUtilsTest {
                /**
                 * 测试删除文件
                 */
                @Test
                public void test5(){
                    FTPUtils ftpUtils = FTPUtils.getInstance();
                    try {
                        ftpUtils.delete("456/ftp.txt");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                
                
                
                /**
                 * 测试下载文件
                 */
                @Test
                public void test4(){
                    FTPUtils ftpUtils = FTPUtils.getInstance();
                    try {
                        ftpUtils.download("D:/", "456/ftp.txt");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                
                
                
                /**
                 * 测试上传文件
                 */
                @Test
                public void test3(){
                    FTPUtils ftpUtils = FTPUtils.getInstance();
                    String dir = "456";
                    File file = new File("D:/eula.2052.txt");
                    try {
                        ftpUtils.upload(dir, true, file);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                
                
                /**
                 * 测试上传文件
                 */
                @Test
                public void test2(){
                    FTPUtils ftpUtils = FTPUtils.getInstance();
                    String dir = "456";
                    File file = new File("D:/eula.2052.txt");
                    try {
                        ftpUtils.upload(dir, file);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                
                
                /**
                 * 根据指定目录
                 *     获取文件与文件夹名称
                 */
                @Test
                public void testListNames(){
                    FTPUtils ftpUtils = FTPUtils.getInstance();
                    try {
                        String[] strs = ftpUtils.listNames("456");
                        for (String string : strs) {
                            System.out.println(string);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

FTP-使用ftp4j操作FTP_3_FTP