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