From c4c2bde0b4a0e8dd68fe2c1eb7b176fe27fc75c0 Mon Sep 17 00:00:00 2001 From: zhaoshengwolf Date: Tue, 13 Dec 2022 09:12:55 +0000 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3FtpTest.java=E7=9A=84download?= =?UTF-8?q?Test=E4=B8=8B=E8=BD=BD=E4=BC=9A=E5=B0=86=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E4=B8=8B=E8=BD=BD=E6=88=90=E6=96=87=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/extra/ftp/FtpTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java index e581c8fd3..beb7e41b8 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java @@ -91,12 +91,19 @@ public class FtpTest { @Test @Ignore public void downloadTest() { - try(final Ftp ftp = new Ftp("localhost")){ - final List fileNames = ftp.ls("temp/"); - for(final String name: fileNames) { - ftp.download("", - name, - FileUtil.file("d:/test/download/" + name)); + String downloadPath = "d:/test/download/"; + try (final Ftp ftp = new Ftp("localhost")) { + final List ftpFiles = ftp.lsFiles("temp/", null); + for (final FTPFile ftpFile : ftpFiles) { + String name = ftpFile.getName(); + if (ftpFile.isDirectory()) { + File dp = new File(downloadPath + name); + if (!dp.exists()) { + dp.mkdir(); + } + } else { + ftp.download("", name, FileUtil.file(downloadPath + name)); + } } } catch (final IOException e) { throw new RuntimeException(e);