|
@@ -17,6 +17,8 @@ import org.apache.commons.net.ftp.FTPSClient;
|
|
|
|
|
|
import nc.pub.Proptool.PropertiesUtil;
|
|
import nc.pub.Proptool.PropertiesUtil;
|
|
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
|
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
|
|
|
+import nc.vo.pubapp.pattern.pub.PubAppTool;
|
|
|
|
+import nccloud.commons.collections.CollectionUtils;
|
|
|
|
|
|
public class FtpsUtil {
|
|
public class FtpsUtil {
|
|
|
|
|
|
@@ -33,13 +35,14 @@ public class FtpsUtil {
|
|
* @param propfilename ftp参数文件
|
|
* @param propfilename ftp参数文件
|
|
* @param type 1对应读取excel文件类型
|
|
* @param type 1对应读取excel文件类型
|
|
* @return 返回类型为Map<String,Object> key =文件名 value=对应的数据
|
|
* @return 返回类型为Map<String,Object> key =文件名 value=对应的数据
|
|
|
|
+ * @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- public Map<String, Object> doFtpReadFile(String propfilename,int type) {
|
|
|
|
|
|
+ public Map<String, Object> doFtpReadFile(String propfilename,int type,String path,List<String> filenamelsit) throws Exception {
|
|
Map<String, Object> result =null;
|
|
Map<String, Object> result =null;
|
|
try {
|
|
try {
|
|
ftpConnectSet(propfilename);
|
|
ftpConnectSet(propfilename);
|
|
- result = readFileList(null, type);
|
|
|
|
|
|
+ result = readFileList(path,filenamelsit, type);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -123,26 +126,30 @@ public class FtpsUtil {
|
|
* @return function:读取指定目录下的文件名
|
|
* @return function:读取指定目录下的文件名
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- private Map<String, Object> readFileList(Map<String, String> mapdir, int type) throws IOException {
|
|
|
|
|
|
+ private Map<String, Object> readFileList(String path,List<String> filenamelsit, int type) throws Exception {
|
|
|
|
+ if(PubAppTool.isNull(path))
|
|
|
|
+ throw new Exception("路径不能为空");
|
|
// 构造返回值
|
|
// 构造返回值
|
|
Map<String, Object> reDatas = new HashMap<String, Object>();
|
|
Map<String, Object> reDatas = new HashMap<String, Object>();
|
|
// 获得指定目录下所有文件名
|
|
// 获得指定目录下所有文件名
|
|
FTPFile[] ftpFiles = null;
|
|
FTPFile[] ftpFiles = null;
|
|
- try {
|
|
|
|
- ftpClient.enterLocalPassiveMode();
|
|
|
|
- ftpFiles = ftpClient.listFiles();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- for (int i = 0; ftpFiles != null && i < ftpFiles.length; i++) {
|
|
|
|
- ftpClient.changeWorkingDirectory(this.basePath);
|
|
|
|
- FTPFile file = ftpFiles[i];
|
|
|
|
- if (file.isFile()) {
|
|
|
|
- String filename = new String(file.getName().getBytes(strencoding), "GBK").toLowerCase();
|
|
|
|
- if (1 == type) {
|
|
|
|
-
|
|
|
|
- ArrayList<ArrayList<Object>> result = readExcelFile(file.getName());
|
|
|
|
- reDatas.put(filename, result);
|
|
|
|
|
|
+ ftpClient.enterLocalPassiveMode();
|
|
|
|
+ //指定目录及文件的直接获取数据
|
|
|
|
+ if(!CollectionUtils.isEmpty(filenamelsit)) {
|
|
|
|
+ for (String filename : filenamelsit) {
|
|
|
|
+ ArrayList<ArrayList<Object>> result = readExcelFile(path+filename);
|
|
|
|
+ reDatas.put(filename, result);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ for (int i = 0; ftpFiles != null && i < ftpFiles.length; i++) {
|
|
|
|
+ ftpClient.changeWorkingDirectory(path);
|
|
|
|
+ FTPFile file = ftpFiles[i];
|
|
|
|
+ if (file.isFile()) {
|
|
|
|
+ String filename = new String(file.getName().getBytes(strencoding), "GBK").toLowerCase();
|
|
|
|
+ if (1 == type) {
|
|
|
|
+ ArrayList<ArrayList<Object>> result = readExcelFile(file.getName());
|
|
|
|
+ reDatas.put(filename, result);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -184,7 +191,6 @@ public class FtpsUtil {
|
|
if (ins != null) {
|
|
if (ins != null) {
|
|
try {
|
|
try {
|
|
ins.close();
|
|
ins.close();
|
|
- // 主动调用一次getReply()把接下来的226消费掉. 这样做是可以解决这个返回null问题
|
|
|
|
ftpClient.getReply();
|
|
ftpClient.getReply();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
// TODO Auto-generated catch block
|