// Path: src/main/cn/ict/zyq/bestConf/cluster/Interface/ConfigWrite.java
// public interface ConfigWrite {
// 	void initial(String server, String username, String password, String localPath, String remotePath);
// 	void uploadConfigFile();
// 	void writetoConfigfile(HashMap hm);
// }
// 
// Path: src/main/cn/ict/zyq/bestConf/cluster/Utils/SFTPUtil.java
// public class SFTPUtil {
// 	
// 	public static ChannelSftp connect(String server, String username, String password) throws JSchException{
// 		Session session = null;
// 		ChannelSftp sftp = null;
// 		try {
// 			JSch jsch = new JSch();
// 			session = jsch.getSession(username, server);
// 			session.setPassword(password);
// 			
// 			session.setConfig("StrictHostKeyChecking", "no");
// 			//time out
// 			session.connect(3000);
// 
// 			sftp = (ChannelSftp) session.openChannel("sftp");
// 			sftp.connect();
// 		} catch (JSchException e) {
// 			e.printStackTrace();
// 			System.out.println("SFTPUitl connection error");
// 			throw e;
// 		}
// 		return sftp;
// 	}
// 	
// 	public static void upload(String directory, String uploadFile, ChannelSftp sftp) throws Exception{
// 		
// 		File file = new File(uploadFile);
// 		if(file.exists()){
// 			
// 			try {
// 				Vector content = sftp.ls(directory);
// 				if(content == null){
// 					sftp.mkdir(directory);
// 					System.out.println("mkdir:" + directory);
// 				}
// 			} catch (SftpException e) {
// 				sftp.mkdir(directory);
// 			}
// 			sftp.cd(directory);
// 			System.out.println("directory: " + directory);
// 			if(file.isFile()){
// 				InputStream ins = new FileInputStream(file);
// 				
// 				sftp.put(ins, new String(file.getName().getBytes(),"UTF-8"));
// 				
// 			}else{
// 				File[] files = file.listFiles();
// 				for (File file2 : files) {
// 					String dir = file2.getAbsolutePath();
// 					if(file2.isDirectory()){
// 						String str = dir.substring(dir.lastIndexOf(file2.separator));
// 						directory = directory + str;
// 					}
// 					System.out.println("directory is :" + directory);
// 					upload(directory,dir,sftp);
// 				}
// 			}
// 		}
// 	}
// 	
// }


import ch.ethz.ssh2.Connection;
import cn.ict.zyq.bestConf.cluster.Interface.ConfigWrite;
import cn.ict.zyq.bestConf.cluster.Utils.SFTPUtil;
import com.jcraft.jsch.ChannelSftp;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

		this.server = server;
		this.username = username;
		this.password = password;
		this.localPath = localPath;
		this.remotePath = remotePath;
		this.sshFileTransConnTimeout = sshFileTransConnTimeout * 1000;
		shellofTransConf = "cd " + "/home/fit/anyanzhe" + ";./filetransfer.exp";
	}


	public void confTransfer() {
		try {
			getConnection();
			if(connection == null)
				throw new IOException("Unable to connect the server!");
			ch.ethz.ssh2.Session session = connection.openSession();
			session.execCommand(shellofTransConf);
			System.out.println("Here is SUT start information:");
			System.out.println("Configuration file had been successfully transfered！");
			if (session != null)
				session.close();
			closeConnection();
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Failed to remove configuration file！");
		}
	}


	public void uploadConfigFile() {

// Path: src/main/cn/ict/zyq/bestConf/cluster/Interface/ConfigWrite.java
// public interface ConfigWrite {
// 	void initial(String server, String username, String password, String localPath, String remotePath);
// 	void uploadConfigFile();
// 	void writetoConfigfile(HashMap hm);
// }
// 
// Path: src/main/cn/ict/zyq/bestConf/cluster/Utils/SFTPUtil.java
// public class SFTPUtil {
// 	
// 	public static ChannelSftp connect(String server, String username, String password) throws JSchException{
// 		Session session = null;
// 		ChannelSftp sftp = null;
// 		try {
// 			JSch jsch = new JSch();
// 			session = jsch.getSession(username, server);
// 			session.setPassword(password);
// 			
// 			session.setConfig("StrictHostKeyChecking", "no");
// 			//time out
// 			session.connect(3000);
// 
// 			sftp = (ChannelSftp) session.openChannel("sftp");
// 			sftp.connect();
// 		} catch (JSchException e) {
// 			e.printStackTrace();
// 			System.out.println("SFTPUitl connection error");
// 			throw e;
// 		}
// 		return sftp;
// 	}
// 	
// 	public static void upload(String directory, String uploadFile, ChannelSftp sftp) throws Exception{
// 		
// 		File file = new File(uploadFile);
// 		if(file.exists()){
// 			
// 			try {
// 				Vector content = sftp.ls(directory);
// 				if(content == null){
// 					sftp.mkdir(directory);
// 					System.out.println("mkdir:" + directory);
// 				}
// 			} catch (SftpException e) {
// 				sftp.mkdir(directory);
// 			}
// 			sftp.cd(directory);
// 			System.out.println("directory: " + directory);
// 			if(file.isFile()){
// 				InputStream ins = new FileInputStream(file);
// 				
// 				sftp.put(ins, new String(file.getName().getBytes(),"UTF-8"));
// 				
// 			}else{
// 				File[] files = file.listFiles();
// 				for (File file2 : files) {
// 					String dir = file2.getAbsolutePath();
// 					if(file2.isDirectory()){
// 						String str = dir.substring(dir.lastIndexOf(file2.separator));
// 						directory = directory + str;
// 					}
// 					System.out.println("directory is :" + directory);
// 					upload(directory,dir,sftp);
// 				}
// 			}
// 		}
// 	}
// 	
// }


// Path: src/iotdb/cn/ict/zyq/bestConf/cluster/InterfaceImpl/IoTDBConfigWrite.java
import ch.ethz.ssh2.Connection;
import cn.ict.zyq.bestConf.cluster.Interface.ConfigWrite;
import cn.ict.zyq.bestConf.cluster.Utils.SFTPUtil;
import com.jcraft.jsch.ChannelSftp;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

		this.server = server;
		this.username = username;
		this.password = password;
		this.localPath = localPath;
		this.remotePath = remotePath;
		this.sshFileTransConnTimeout = sshFileTransConnTimeout * 1000;
		shellofTransConf = "cd " + "/home/fit/anyanzhe" + ";./filetransfer.exp";
	}


	public void confTransfer() {
		try {
			getConnection();
			if(connection == null)
				throw new IOException("Unable to connect the server!");
			ch.ethz.ssh2.Session session = connection.openSession();
			session.execCommand(shellofTransConf);
			System.out.println("Here is SUT start information:");
			System.out.println("Configuration file had been successfully transfered！");
			if (session != null)
				session.close();
			closeConnection();
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Failed to remove configuration file！");
		}
	}


	public void uploadConfigFile() {

		SFTPUtil sftpUtil = new SFTPUtil();
