/*
 * MasterCrtAgentPollingAction.java	2011. 03. 17
 *
 * Copyright 2011 FUJITSU KOREA LTD. All rights reserved.
 * FUJITSU KOREA LTD PROPRIETARY/CONFIDENTIAL. 
 * Use is subject to license terms.
 */
package biz.cms_FileAgent;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import kr.fujitsu.com.ffw.daemon.core.DaemonConfigLocator;
import kr.fujitsu.com.ffw.daemon.core.config.repository.property.PropertyUtil;
import kr.fujitsu.com.ffw.daemon.net.polling.PollingAction;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.log4j.Logger;


import biz.comm.CompressionUtil;
import biz.comm.JSCHFTPManager;
import biz.comm.SFTPManager;


/** 
 * MasterAgentPollingAction
 * Kiosk 파일 압축 및 Ftp serve 전송
 * @created  on 1.0,  2019.02.18
 * @created  by Zin corp. 
 *  
 * @modified on 
 * @modified by 
 * @caused   by 
 */ 

public class FileAgentPollingAction extends PollingAction {
	private static Logger logger = Logger.getLogger(FileAgentPollingAction.class);

	//private final int MAX_TARGET_NUM = 30;

	public static void main(String args[]) throws Exception {
		FileAgentPollingAction action = new FileAgentPollingAction();

		logger.debug("▶ " + " FileAgent main args null");

		try {
			if (args == null || args.length < 1) {
				logger.debug("▶ " + " master main args null");
			}
			String path          = nvl(args[0].replaceFirst("-path:"  ,""));

			DaemonConfigLocator locator = DaemonConfigLocator.getInstance("xml",path);
			action.execute("1");

		}catch(Exception e) {
			logger.debug("[ERROR]" + e.getMessage());
		}
	}

	private static String nvl(String param) {
		return param != null ? param: "";
	}

	public void execute(String actionMode ) {

		try {
			PropertyUtil pu = new PropertyUtil();
			//String server_no = pu.findProperty("stsys-property", "SERVER_NO");
			String server_no = "1";

			if (actionMode.equals("1") && server_no.equals("1")) {

				FileAgentDAO dao   = new FileAgentDAO();
				Calendar calendar = new GregorianCalendar(Locale.KOREA);
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
				calendar.setTime(new Date());
				String today = sdf.format(calendar.getTime());

				//calendar.add(Calendar.DATE, 1);
				//String sale_dt = sdf.format(calendar.getTime());

				HashMap hm = new HashMap();

				/*hm.put("FTP_SERVER", pu.findProperty("stsys-property", "FTP_SERVER_IP"));
				hm.put("FTP_ID", pu.findProperty("stsys-property", "FTP_SERVER_ID"));
				hm.put("FTP_PWD", pu.findProperty("stsys-property", "FTP_SERVER_PWD"));
				hm.put("FTP_PORT",Integer.parseInt(pu.findProperty("stsys-property", "FTP_SERVER_PORT")));
				hm.put("FTP_POS_PORT",Integer.parseInt(pu.findProperty("stsys-property", "FTP_POS_PORT"))); 
				hm.put("USER_HOME","/home/hs_dev");
				hm.put("FTP_USER_HOME", pu.findProperty("stsys-property", "FTP_USER_HOME")) ;
				hm.put("DAY_CNT", pu.findProperty("stsys-property", "FTP_USER_HOME")) ;*/

				/*hm.put("FTP_SERVER", "10.0.40.148");
				hm.put("FTP_ID", "stationftp");
				hm.put("FTP_PWD", "R+n0Ef}?%]");
				hm.put("FTP_PORT","22");
				hm.put("FTP_POS_PORT","21"); 
				hm.put("USER_HOME","/home/hs_dev");
				hm.put("FTP_USER_HOME", "/ftp_home/stationftp/dev/CMBO") ;
				hm.put("DAY_CNT", "/ftp_home/stationftp/dev/CMBO") ;*/
				
				/*hm.put("FTP_SERVER", "211.108.6.162");
				hm.put("FTP_ID", "Nftp_nhs");
				hm.put("FTP_PWD", "L6y7V>gxU\\");
				hm.put("FTP_PORT","22");
				hm.put("FTP_POS_PORT","21"); 
				hm.put("USER_HOME","/home/hs_dev");
				hm.put("FTP_USER_HOME", "/data/Nftp_nhs/dev/CMBO") ;
				hm.put("DAY_CNT", "/data/Nftp_nhs/dev/CMBO") ;*/
				
				
				hm.put("FTP_SERVER", pu.findProperty("stsys-property","FTP_SERVER_IP")); //10.0.40.148");
				hm.put("FTP_ID", pu.findProperty("stsys-property","FTP_SERVER_ID")); //"nhsftp");
				hm.put("FTP_PWD", pu.findProperty("stsys-property","FTP_SERVER_PWD")); //"aj9upe%DPv");
				hm.put("FTP_PORT",pu.findProperty("stsys-property","FTP_POS_PORT")); //"15638");
				hm.put("FTP_POS_PORT",pu.findProperty("stsys-property","FTP_POS_PORT")); //"15638"); 
				hm.put("USER_HOME",pu.findProperty("stsys-property","FTP_USER_HOME")); //"/home/hs_dev/files");
				//hm.put("FTP_USER_HOME", "/data/Nftp_nhs/dev/CMBO") ;
				hm.put("FTP_USER_HOME", pu.findProperty("stsys-property","FTP_USER_HOME_NEW")) ; ///nas/nhs/nhs/CMBO
				hm.put("FTP_USER_HOME_NEW", pu.findProperty("stsys-property","FTP_USER_HOME_NEW")); ///nas/nhs/nhs/CMBO
				hm.put("FTP_USER_HOME_REAL", pu.findProperty("stsys-property","FTP_USER_HOME_REAL")); ///nas/nhs/nhs/CMBO
				hm.put("DAY_CNT", pu.findProperty("stsys-property","FTP_USER_HOME_NEW")) ;
				
				
				//법인 회사별 영업일 조회 
				String deploy_dt = dao.getSysDate("BRKR" ,0);  

				//logger.debug("[INIT] deploy_dt - " + deploy_dt);

				//백업기간 일자는 각 파일별로 다를 수 있음 3일치?
				String deploy_dt2 =dao.getSysDate("BRKR" ,4);	
				//logger.debug("[INIT] deploy_dt2 - " + deploy_dt2);


				//영업일 4일전부터 오늘까지
				//List ls = new ArrayList();



				//ls.add("20190307");

				List ls = dao.getbetweenDate("BRKR" , deploy_dt2 , deploy_dt); 


				//total 이미지 파일 삭제 처리 
				//DeleteCDPCOMFile("PCKR",hm);				
				//DeletCustomerFile("PCKR",hm); 


				//file div  11: item 12: optn 13: CATE 14 :cate 15: screen 16: present 17: PRD_TAG 18: LOGO

				// makeItemImageCreate("PCKR","002",deploy_dt,"ITEM","ITEM",ls,hm,"11"); 
				// makeItemImageCreate("PCKR","002",deploy_dt,"OPTN","OPTN",ls,hm,"12"); 
				// makeItemImageCreate("PCKR","002",deploy_dt,"CAMPN","CAMPN",ls,hm,"13"); 
				// makeItemImageCreate("PCKR","002",deploy_dt,"CATE","CATE",ls,hm,"14"); 
				// makeItemImageCreate("PCKR","002",deploy_dt,"SCREEN","SCREEN",ls,hm,"15"); 
				// makeItemImageCreate("PCKR","002",deploy_dt,"PRESENT","PRESENT",ls,hm,"16");
				// makeItemImageCreate("PCKR","002",deploy_dt,"TAG","TAG",ls,hm,"17");
				// makeItemImageCreate("PCKR","002",deploy_dt,"LOGO","LOGO",ls,hm,"18");

				logger.debug("[PROCESS] START ");

				makeItemImageCreate("BRKR","5000",deploy_dt,"ITEM","ITEM",ls,hm,"11"); 
				makeItemImageCreate("BRKR","5000",deploy_dt,"OPTN","OPTN",ls,hm,"12"); 
				makeItemImageCreate("BRKR","5000",deploy_dt,"CAMPN","CAMPN",ls,hm,"13"); 
				makeItemImageCreate("BRKR","5000",deploy_dt,"CATE","CATE",ls,hm,"14"); 
				makeItemImageCreate("BRKR","5000",deploy_dt,"SCREEN","SCREEN",ls,hm,"15"); 
				makeItemImageCreate("BRKR","5000",deploy_dt,"PRESENT","PRESENT",ls,hm,"16");
				makeItemImageCreate("BRKR","5000",deploy_dt,"TAG","TAG",ls,hm,"17");
				makeItemImageCreate("BRKR","5000",deploy_dt,"LOGO","LOGO",ls,hm,"18");

				logger.debug("[PROCESS] END ");

				//makeOptnImageCreate("PCKR","OPTN",hm); //부가옵션이미지
				//makeCampnImageCreate("PCKR","CAMPN",hm); //캠페인배너이미지
				//makeCateImageCreate("PCKR","CATE",hm); //제품카테고리이미지
				//makeScreenImageCreate("PCKR","SCREEN",hm);//대기화면 이미지/동영상
				//makePresentImageCreate("PCKR","PRESENT",hm);//사은품이미지

			}
		}

		catch (Exception e) {
			logger.debug("[ERROR] " + e.toString());
			System.out.println("[ERROR] " + e.toString());
		} catch (Throwable e) {
			logger.debug("[ERROR2] " + e.toString());
			System.out.println("[ERROR2] " + e.toString());
			e.printStackTrace();
		}
	}

	//상품이미지
	private void makeItemImageCreate(String cmp_cd, String sales_org_cd,String deploy_dt, String imageKindWeb, String imageKindPos, List ls,HashMap hm, String fileDiv )  throws Exception {
		FileAgentDAO dao   = new FileAgentDAO(); 
		CompressionUtil cu = new CompressionUtil(); 

		//1.WEB에서 업로드된 파일 폴더  --> /home/hs_dev/upload/PCKR/002/ITEM
		String webitem_imgdir = (String)hm.get("USER_HOME") + File.separator +
				"upload" + File.separator + 
				cmp_cd +  File.separator +
				sales_org_cd +  File.separator + 
				imageKindWeb;

		//2.POS 압축하기 위한 파일 폴더 --> /home/hs_dev/CMBO/temp/PCKR/002/CDP/ITEM/
		String positem_zipMakedir =(String)hm.get("USER_HOME") + File.separator +
				"CMBO/temp" +  File.separator+  
				cmp_cd +  File.separator + 
				sales_org_cd +  File.separator +
				"CDP" +  File.separator+
				imageKindPos;	
		//3. POS 압축하기 위한 파일 폴더 전체 -->      /home/hs_dev/CMBO/temp/PCKR/002/CDP
		String positem_zipdir =(String)hm.get("USER_HOME")+ File.separator +
				"CMBO/temp" +  File.separator +
				cmp_cd +  File.separator +
				sales_org_cd +  File.separator +
				"CDP";  
		//4. POS 전체폴더 --> /home/hs_dev/CMBO/TOTAL/CDP/ITEM
		String positem_backupimgdir =	(String)hm.get("USER_HOME") + File.separator +
				"CMBO" + File.separator +
				"TOTAL/CDP" +  File.separator+
				imageKindPos;// 전체 백업 저장 폴더
		//5. POS total 압축폴더 --> /home/hs_dev/CMBO/TOTAL/CDP/
		String positem_totzipdir =(String)hm.get("USER_HOME") + File.separator +
								  "CMBO"  + File.separator + 
								  "TOTAL" + File.separator +
								  "CDP"; 
		
		//6. new folder
		String nhs_zipdir = (String)hm.get("USER_HOME") + File.separator +
							  "CMBO"  + File.separator +
							  "CDP"  + File.separator +
							  imageKindPos;
		
		// 전체 img 압축 명--> PCKR_POS_ITEM_TOTALIMG.ZIP
		String positem_totzipNm = cmp_cd + "_"+ sales_org_cd + "_"+ "POS_"+ imageKindPos +"_TOTALIMG.ZIP";

		try {

			//압축할 temp 폴더 생성
			logger.debug("pos positem_zipMakedir --->" + positem_zipMakedir);
			dao.mkDir(positem_zipMakedir);  // /home/hs_dev/CMBO/temp/PCKR/002/CDP/ITEM/
			if(ls == null){//테스트용
				Map<String, String> map = new HashMap<String,String>();
				map.put("SYS_DATE","20190327");

				List dirList =  dao.getDirFileList(webitem_imgdir   + File.separator + ((String)map.get("SYS_DATE")).substring(0,4) 
						+ File.separator + ((String)map.get("SYS_DATE")).substring(4,6) 
						+ File.separator + ((String)map.get("SYS_DATE")).substring(6,8));


				if (dirList.size()> 0 ) {		// 웹경로에 파일이 존재하는 경우 
					logger.debug("action file copy start " + dirList.size());
					// 4.신규 이미지 카피 
					for(int k = 0;k < dirList.size();k++) { 
						try {
							dao.fileCopy(webitem_imgdir 
									+ File.separator + ((String)map.get("SYS_DATE")).substring(0,4) 
									+ File.separator + ((String)map.get("SYS_DATE")).substring(4,6) 
									+ File.separator + ((String)map.get("SYS_DATE")).substring(6,8) + File.separator + dirList.get(k) 
									,positem_zipMakedir+File.separator + dirList.get(k));
						} catch (Exception e) {
							logger.debug(" file backup copy err " + e.toString());
						} catch (Throwable e) {
							e.printStackTrace();
						}
					}
				} 

			}else{
				if (ls.size()>0){// 일별 폴더 체크 
					for(int row = 0; row < ls.size(); row ++){
						Map<String, String> map = (Map<String, String>)ls.get(row);

						logger.debug((String)map.get("SYS_DATE"));


						List dirList =  dao.getDirFileList(webitem_imgdir   + File.separator + ((String)map.get("SYS_DATE")).substring(0,4) 
								+ File.separator + ((String)map.get("SYS_DATE")).substring(4,6) 
								+ File.separator + ((String)map.get("SYS_DATE")).substring(6,8));

						if (dirList.size()> 0 ) {		// 파일이 존재하는 경우 
							logger.debug("action file copy start " + dirList.size());
							// 4.신규 이미지 카피 
							for(int k = 0;k < dirList.size();k++) { 
								try {
									dao.fileCopy(webitem_imgdir 
											+ File.separator + ((String)map.get("SYS_DATE")).substring(0,4) 
											+ File.separator + ((String)map.get("SYS_DATE")).substring(4,6) 
											+ File.separator + ((String)map.get("SYS_DATE")).substring(6,8) + File.separator + dirList.get(k) 
											,positem_zipMakedir+File.separator + dirList.get(k));
								} catch (Exception e) {
									logger.debug(" file backup copy err " + e.toString());
								} catch (Throwable e) {
									e.printStackTrace();
								}
							}
						} 
					} 
				}
			}
			String basePath = (String)hm.get("USER_HOME") + File.separator +
					"CMBO"  +"/POS/UPLOAD";	// 파일 생성 루트

			//logger.debug("[INFO] basePath - " + basePath);

			//String fileName =cmp_cd+ "_"+sales_org_cd +"_"+ imageKindPos+"_" + "0000T" + ".zip";
			String fileName =cmp_cd+ "_"+sales_org_cd +"_"+ imageKindPos+"_" + dao.getFileNm(cmp_cd, deploy_dt, fileDiv) + ".zip";

			//logger.debug("[INFO] fileName - " + fileName);

			File[] filelist =  new File(positem_zipMakedir).listFiles(); 
			if (filelist.length >0) {	 
				cu.zip(new File(positem_zipMakedir) , new File(basePath)  , "UTF-8",  true ,fileName.toString());

				File sftpfile = new File(basePath +File.separator + fileName.toString() );  

				//전체 파일 COPY 처리 
				// positem_zipMakedir : /home/hs_dev/CMBO/temp/PCKR/002/CDP/ITEM/
				// positem_backupimgdir : /home/hs_dev/CMBO/TOTAL/CDP/ITEM
				// positem_totzipdir : /home/hs_dev/CMBO/TOTAL/CDP/
				//int retvalue = dao.setDirFileList(positem_zipMakedir, positem_backupimgdir); //--에러..	 					
				
				String uploadPath=(String)hm.get("FTP_USER_HOME")  + "/CDP/"+imageKindPos+"/";
				String uploadViewPath = (String)hm.get("FTP_USER_HOME_REAL")  + "/CDP/"+imageKindPos+"/";
				
				//신규 테스트
				cu.zip(new File(positem_zipMakedir) , new File(nhs_zipdir)  , "UTF-8",  true ,fileName.toString());
				
				ArrayList<String> ftplist = new ArrayList<String>();
				ftplist.add(fileName.toString());

//				String localIp =  this.getLocalServerIp();
//
//				logger.debug("[INFO] getLocalServerIp - " + localIp);
//
//				String server1 = (String) hm.get("FTP_SERVER");
//				String server2 = (String) hm.get("FTP_SERVER2");
//				
//				if(localIp.equals(server1) || localIp.equals(server2)) {
//
//					logger.debug("[INFO] local file copy start");
//
//					String target = (String) hm.get("USER_HOME_NAS");
//					String targetUploadPath = target + "/CDP/"+imageKindPos+"/";
//
//					String downPath = targetUploadPath + File.separator + sftpfile.getName();
//
//					try {
//						FileInputStream fis = new FileInputStream(basePath +File.separator + fileName.toString());
//						FileOutputStream fos = new FileOutputStream(downPath);
//
//						int data = 0;
//						while((data=fis.read())!=-1) {
//							fos.write(data);
//						}
//						fis.close();
//						fos.close();
//
//					} catch (IOException e) {
//						// TODO Auto-generated catch block
//						logger.debug("[ERROR] local file copy fail");
//					}
//
//					logger.debug("[INFO] local file copy end");
//
//				} else {
//					String port = String.valueOf(hm.get("FTP_PORT"));
//					JSCHFTPManager  jsFtpMgr =null ;
//					jsFtpMgr = new JSCHFTPManager(
//							(String)hm.get("FTP_SERVER"), 
//							Integer.parseInt(port) , 
//							(String)hm.get("FTP_ID"),
//							(String)hm.get("FTP_PWD") 
//							);
//
//					//10.당일분  upload 
//					String downPath = uploadPath
//							+ File.separator + sftpfile.getName();
//
//					logger.debug("[PROCESS] downPath - " + downPath);
//
//					File uploadFile = new File(basePath +File.separator + fileName);
//
//					//					jsFtpMgr.upload(basePath +File.separator + fileName, remoteFile);
//					jsFtpMgr.upload(uploadPath, uploadFile);
//				}

				/*
				boolean re = sendFtpServer((String)hm.get("FTP_SERVER"),
					   			(String)hm.get("FTP_PORT"), 
				    		  (String)hm.get("FTP_ID"),
				    		  (String)hm.get("FTP_PWD"),
	 			    		  uploadPath,
	 			    		  basePath +File.separator , 
	 			    		  ftplist);
				 */
				//				String port = String.valueOf(hm.get("FTP_PORT"));
				//				JSCHFTPManager  jsFtpMgr =null ;
				//					jsFtpMgr = new JSCHFTPManager(
				//						(String)hm.get("FTP_SERVER"), 
				//						Integer.parseInt(port) , 
				//						(String)hm.get("FTP_ID"),
				//						(String)hm.get("FTP_PWD") 
				//						);
				//
				//		        //10.당일분  upload 
				//				String downPath = uploadPath
				//				+ File.separator + sftpfile.getName();
				//				
				//				logger.debug("[PROCESS] downPath - " + downPath);
				//				
				//				File uploadFile = new File(basePath +File.separator + fileName);
				//				
				////				jsFtpMgr.upload(basePath +File.separator + fileName, remoteFile);
				//				jsFtpMgr.upload(uploadPath, uploadFile);

				//logger.debug("[PROCESS] jsFtpMgr.upload");

				//				String port = String.valueOf(hm.get("FTP_PORT"));
				//                (new StringBuilder(String.valueOf(uploadPath))).append(File.separator).append(sftpfile.getName()).toString();
				//                new File(basePath + File.separator + fileName);

				if (!sftpfile.getName().equals("")){
					//** 배치성으로 프로그램 실행시에는 stsys-property.xml 에 브랜드 회사코드 정보 저장 
					logger.debug("Database" +  "database 생성중 " + filelist.length );
					try{ 
						Map mapFile = new HashMap();
						mapFile.put("SALE_DT", deploy_dt);
						mapFile.put("CMP_CD", cmp_cd);
						mapFile.put("SALES_ORG_CD", sales_org_cd);
						mapFile.put("FILE_NM", fileName);
						mapFile.put("STOR_CD", "");
						mapFile.put("FILE_PATH",uploadViewPath); 
						//"/data/nhs_ftp/CMBO"+ "/CDP/" + imageKindPos + File.separator);
						mapFile.put("DEPLOY_DIV", fileDiv); 				
						//2.배신 테이블에 데이터 생성 
						int ret = dao.procMSTINFOCRT(mapFile);
					}catch(SQLException e){
						logger.debug("[ERROR] " + e.toString()); 
					}
				}

			}else{
				logger.debug("[file not found]"); 
			}

		} catch(Exception e) {
			logger.debug("[ERROR] " + e.toString()); 
		} finally { 
			// 작업 완료 후 폴더 삭제 
			dao.deleteDirectory(new File(positem_zipMakedir));
		}   

	}

	// 브랜드별 파일 생성  관련 프로그램 소스 추가 시작 2017.04.24 끝 
	private String getLocalServerIp()
	{
		try
		{
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
			{
				NetworkInterface intf = en.nextElement();
				for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
				{
					InetAddress inetAddress = enumIpAddr.nextElement();
					if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress())
					{
						return inetAddress.getHostAddress().toString();
					}
				}
			}
		}
		catch (SocketException ex) {}
		return null;
	} 


	public boolean sendFtpServer(String ip, String port, String id, String password,
			String folder,String localPath, ArrayList<String> files) {

		boolean isSuccess = false;
		FTPClient ftp = null;
		int reply;
		try {

			ftp = new FTPClient();
			ftp.setControlEncoding("UTF-8");
			ftp.connect(ip, Integer.parseInt(port));
			logger.info("Connected to " + ip + " on "+ftp.getRemotePort());

			// After connection attempt, you should check the reply code to verify
			// success.
			reply = ftp.getReplyCode();
			if (!FTPReply.isPositiveCompletion(reply)) {
				ftp.disconnect();
				logger.info("FTP server refused connection.");
				System.exit(1);
			}

			if(!ftp.login(id, password)) {
				ftp.logout();
				logger.info("ftp 서버에 로그인하지 못했습니e");	
				//throw new Exception("ftp 서버에 로그인하지 못했습니다.");
			}

			ftp.setFileType(FTP.BINARY_FILE_TYPE);
			ftp.enterLocalPassiveMode();            

			logger.info(ftp.printWorkingDirectory());
			try{
				ftp.makeDirectory(folder);
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString());
			}
			ftp.changeWorkingDirectory(folder);
			logger.info(ftp.printWorkingDirectory());

			for(int i = 0; i < files.size(); i++) {
				String sourceFile = localPath + files.get(i);        
				File uploadFile = new File(sourceFile);
				FileInputStream fis = null;
				try {
					fis = new FileInputStream(uploadFile);
					logger.info(sourceFile + " : 전송시작 = >");
					//logger.info
					isSuccess = ftp.storeFile(files.get(i), fis);
					logger.info(sourceFile + " : 전송결과 = >" + isSuccess);
				} catch(IOException e) {
					e.printStackTrace();

					logger.error( "send err" + e.toString());
					isSuccess = false;
				} finally {
					if (fis != null) {
						try {
							fis.close();
							logger.info( "send final ok" );

						} catch(IOException e) 
						{ 
							logger.error( "send final err" + e.toString());
						}
					}
				}//end try
			}//end for

			ftp.logout();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (ftp != null && ftp.isConnected()) {
				try { ftp.disconnect(); } catch (IOException e) {}
			}
		}
		return isSuccess;
	}
}
