diff --git a/common/src/main/java/com/foreverwin/mesnac/common/ftp/CappFtpClient.java b/common/src/main/java/com/foreverwin/mesnac/common/ftp/CappFtpClient.java index 3a132d49..9418f852 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/ftp/CappFtpClient.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/ftp/CappFtpClient.java @@ -3,6 +3,7 @@ package com.foreverwin.mesnac.common.ftp; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClientConfig; import org.apache.commons.net.ftp.FTPFile; +import org.apache.commons.net.ftp.FTPReply; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @@ -329,5 +330,23 @@ public class CappFtpClient { throw ioe; } } + public FTPClient login() throws IOException{ + this.ftp=new FTPClient(); + this.ftp.connect(address,port); + + if(FTPReply.isPositiveCompletion(this.ftp.getReplyCode())){ + if(this.ftp.login(userName, password)){ + this.ftp.setControlEncoding("GBK"); + return this.ftp; + } + } + if(this.ftp.isConnected()){ + this.ftp.disconnect(); + + } + + return this.ftp; + + } } diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/FileServiceImpl.java b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/FileServiceImpl.java index 0518032c..329b248d 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/FileServiceImpl.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/FileServiceImpl.java @@ -39,10 +39,9 @@ public class FileServiceImpl implements FileService { FTPClient connect = null; Map pathMap = new HashMap<>(); try { - connect = cappFtpClient.connect(); - //更换目录到当前目录 - connect.enterLocalPassiveMode(); + connect = cappFtpClient.login(); connect.changeWorkingDirectory(path); + connect.enterLocalPassiveMode(); FTPFile[] files = connect.listFiles(); if(files!=null){ for (int i = 0; i < files.length; i++) {