Prechádzať zdrojové kódy

处理ftp导入失败问题

longht 3 rokov pred
rodič
commit
c29ec1171a

+ 10 - 10
src/private/nc/impl/pubdev/pubtool/execmethod/FtpUtil.java

@@ -34,16 +34,17 @@ public class FtpUtil {
      * @param propfilename  ftp参数文件
      * @param type 1对应读取excel文件类型
      * @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) throws Exception {
 		Map<String, Object> result =null;
 		try {
 			ftpConnectSet(propfilename);
 			result = readFileList(null, type);
-		} catch (IOException e) {
+		} catch (Exception e) {
 			// TODO Auto-generated catch block
-			e.printStackTrace();
+			throw new Exception(e.getMessage());
 		} finally {
 			closeServer();
 		}
@@ -53,7 +54,7 @@ public class FtpUtil {
 
 	
 	//设置ftp连接参数
-	private void ftpConnectSet(String propfilename) {
+	private void ftpConnectSet(String propfilename) throws Exception {
 		
 		ip = PropertiesUtil.getProperty(propfilename, "ftp_ip");
 		userName = PropertiesUtil.getProperty(propfilename, "ftp_username");
@@ -71,10 +72,11 @@ public class FtpUtil {
 	 * @param userName
 	 * @param userPwd
 	 * @param path
+	 * @throws Exception 
 	 * @throws SocketException
 	 * @throws IOException     function:连接到服务器
 	 */
-	private  void connectServer(String ip, int port, String userName, String userPwd, String path) {
+	private  void connectServer(String ip, int port, String userName, String userPwd, String path) throws Exception {
 		ftpClient = new FTPClient();
 		try {
 			ftpClient.setDataTimeout(300 * 1000);
@@ -89,12 +91,10 @@ public class FtpUtil {
 				ftpClient.changeWorkingDirectory(path);
 				strencoding = ftpClient.getControlEncoding();
 			}
-		} catch (SocketException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
+		} catch (Exception e) {
+			throw new Exception("ftp连接失败:"+e.getMessage());
+		  }
 		}
-	}
 
 	/**
 	 * 关闭连接

+ 8 - 9
src/private/nc/impl/pubdev/pubtool/execmethod/FtpsUtil.java

@@ -44,9 +44,9 @@ public class FtpsUtil {
 		try {
 			ftpConnectSet(propfilename);
 			result = readFileList(path,filenamelsit, type);
-		} catch (IOException e) {
+		} catch (Exception e) {
 			// TODO Auto-generated catch block
-			e.printStackTrace();
+			throw new Exception(e.getMessage());
 		} finally {
 			closeServer();
 		}
@@ -56,7 +56,7 @@ public class FtpsUtil {
 
 	
 	//设置ftp连接参数
-	private void ftpConnectSet(String propfilename) {
+	private void ftpConnectSet(String propfilename) throws Exception {
 		
 		ip = PropertiesUtil.getProperty(propfilename, "ftp_ip");
 		userName = PropertiesUtil.getProperty(propfilename, "ftp_username");
@@ -74,10 +74,11 @@ public class FtpsUtil {
 	 * @param userName
 	 * @param userPwd
 	 * @param path
+	 * @throws Exception 
 	 * @throws SocketException
 	 * @throws IOException     function:连接到服务器
 	 */
-	private  void connectServer(String ip, int port, String userName, String userPwd, String path) {
+	private  void connectServer(String ip, int port, String userName, String userPwd, String path) throws Exception {
 		ftpClient = new FTPSClient("TLS", true);
 		try {
 			ftpClient.setDataTimeout(300 * 1000);
@@ -93,11 +94,9 @@ public class FtpsUtil {
 				ftpClient.changeWorkingDirectory(path);
 				strencoding = ftpClient.getControlEncoding();
 			}
-		} catch (SocketException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
+		} catch (Exception e) {
+			throw new Exception("ftp连接失败:"+e.getMessage());
+		} 
 	}
 
 	/**

+ 6 - 1
src/private/nc/impl/pubdev/pubtool/filetool/DevFileGainToolimpl.java

@@ -22,7 +22,12 @@ public class DevFileGainToolimpl implements IDevFileGainTool{
 	@Override
 	public Map<String, Object> GainDatasByFtp(String propfilename, int type) throws BusinessException {
 		// TODO Auto-generated method stub
-		return new FtpUtil().doFtpReadFile(propfilename, type);
+		try {
+			return new FtpUtil().doFtpReadFile(propfilename, type);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			throw new BusinessException(e.getMessage());
+		}
 	}
 
 	@Override