package com.steering.pss.sale.order.craftDesign.server;


import com.steering.comm.file.CoreFTPClient;

public class FTPTool {
	public static String[] CopyFile(String srcFilePath, String path){
		String[] results = new String[2];
		if(srcFilePath.equals("")){
			results[0] = "";
			results[1] = "";
			return results;
		}else{
			if(!srcFilePath.contains("/ftp/ftpuser/")){
				srcFilePath = "/ftp/ftpuser/"+srcFilePath;
			}
		}
		if(!path.equals("")&&!path.contains("/ftp/ftpuser/")){
			path = "/ftp/ftpuser/"+path;
		}
		CoreFTPClient ftp = CoreFTPClient.newInstance();
		String name = "";
		if(srcFilePath.contains("\\")){
			name = srcFilePath.substring(srcFilePath.lastIndexOf('\\') + 1);
		}else{
			name = srcFilePath.substring(srcFilePath.lastIndexOf('/') + 1);
		}
				
		try {
			ftp.open();
			byte[] bFile = ftp.Download(srcFilePath);
			ftp.upload(bFile, name, path);
			ftp.close();
		} catch (Exception e) {
			results[0] = "False";
			results[1] = "图片地址："+srcFilePath+" 目录"+path +" 名称"+ name;
			return results;
		}finally{
			try {
				ftp.close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
		results[0] = "";
		results[1] = path + name;
		return results;
	}
	
	public static String DeletePath(String path){
		if(path.equals("")){
			return "";
		}
		CoreFTPClient ftp = CoreFTPClient.newInstance();
		try {
			ftp.open();
			ftp.deletePath(path);
			ftp.close();
		} catch (Exception e) {
			return "False";
		}finally{
			try {
				ftp.close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
		return "";
	}
}
