Subversion Repositories SmartDukaan

Rev

Rev 6848 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.serving.services;

import java.util.Arrays;
import java.util.List;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.optional.ssh.Scp;

import in.shop2020.config.ConfigException;
import in.shop2020.thrift.clients.config.ConfigClient;
import org.apache.log4j.Logger;


public class ScpService {
        
        private static Logger log = Logger.getLogger(Class.class);
        public List<String> ips;
        public String keyFile;

    public void scpFile( String remoteFilePath, String localFilePath ) throws ConfigException {
        
                List<String> ips = Arrays.asList((ConfigClient.getClient().get("ips_for_banner_uploading")).split(" "));
                if ( !(ips.get(0).equalsIgnoreCase("NA"))){
                        keyFile= ConfigClient.getClient().get("secret_key_file");
                        for(int i=0;i<ips.size();i+=1){
                                log.info("ip:"+ips.get(i)+":i:"+i+":secret_key_file:"+keyFile);
                        Scp scp = new Scp();
                        scp.setFile(localFilePath);
                        log.info("Banner Uploading paths Local Path: "+localFilePath+"Remote Path :"+remoteFilePath);
                        scp.setKeyfile(keyFile);
                        scp.setRemoteTodir("root: @"+ips.get(i)+":"+remoteFilePath);
                        scp.setProject(new Project());
                        scp.setTrust(true);
                        scp.execute();
                        log.info("Scp executed on IP:"+ips.get(i));
                        }
                }
                /*Scp scp = new Scp();
            scp.setFile(localFilePath);
            log.info(localFilePath);
            log.info(remoteFilePath);
            scp.setKeyfile("/usr/share/tomcat6/id_rsa");
            scp.setRemoteTodir("root: @shop2020.in:"+remoteFilePath);
            scp.setProject(new Project());
            scp.setTrust(true);
            scp.execute();*/
                
                
                } 

    public static void main(String[] args) throws ConfigException {
        ScpService scp = new ScpService();
        scp.scpFile("/var/lib/tomcat6/webapps/export/banners/banner1.jpg", "/var/lib/tomcat6/webapps/export/banners/banner1.jpg");
    }

}