解决FtpTest.java的downloadTest下载会将文件夹下载成文件的问题

This commit is contained in:
zhaoshengwolf 2022-12-13 09:12:55 +00:00
parent 47479f45a7
commit c4c2bde0b4

View File

@ -91,12 +91,19 @@ public class FtpTest {
@Test @Test
@Ignore @Ignore
public void downloadTest() { public void downloadTest() {
String downloadPath = "d:/test/download/";
try (final Ftp ftp = new Ftp("localhost")) { try (final Ftp ftp = new Ftp("localhost")) {
final List<String> fileNames = ftp.ls("temp/"); final List<FTPFile> ftpFiles = ftp.lsFiles("temp/", null);
for(final String name: fileNames) { for (final FTPFile ftpFile : ftpFiles) {
ftp.download("", String name = ftpFile.getName();
name, if (ftpFile.isDirectory()) {
FileUtil.file("d:/test/download/" + name)); File dp = new File(downloadPath + name);
if (!dp.exists()) {
dp.mkdir();
}
} else {
ftp.download("", name, FileUtil.file(downloadPath + name));
}
} }
} catch (final IOException e) { } catch (final IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);