master
philip 3 years ago
parent 76537ddf21
commit a3f7f29024

@ -3,6 +3,7 @@ package com.foreverwin.mesnac.common.ftp;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig; import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -329,5 +330,23 @@ public class CappFtpClient {
throw ioe; 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;
}
} }

@ -39,10 +39,9 @@ public class FileServiceImpl implements FileService {
FTPClient connect = null; FTPClient connect = null;
Map<String,String> pathMap = new HashMap<>(); Map<String,String> pathMap = new HashMap<>();
try { try {
connect = cappFtpClient.connect(); connect = cappFtpClient.login();
//更换目录到当前目录
connect.enterLocalPassiveMode();
connect.changeWorkingDirectory(path); connect.changeWorkingDirectory(path);
connect.enterLocalPassiveMode();
FTPFile[] files = connect.listFiles(); FTPFile[] files = connect.listFiles();
if(files!=null){ if(files!=null){
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {

Loading…
Cancel
Save