paulushcgcj
11/8/2016 - 9:36 PM

Classe utils para fazer SSH

Classe utils para fazer SSH

public static boolean uploadTo(String usuario,String senha, String host, int porta,String destino,String dirDestino, String arquivo){
  criaDir(usuario, senha, host, porta, dirDestino);
	ShellConnectionStream ssh = new ShellConnectionStream(usuario, senha, host, porta);
	try{
		ssh.connect();
		if(ssh.isReady()) {
			if(ssh.upload(arquivo,destino, dirDestino)){
				ssh.close();
				return true;				
			}
		}
	} catch(Exception e){ e.printStackTrace(); }		
	return false;
}

public static boolean uploadTo(String usuario,String senha, String host, int porta,String dirDestino, List<String> arquivos){
	criaDir(usuario, senha, host, porta, dirDestino);
	ShellConnectionStream ssh = new ShellConnectionStream(usuario, senha, host, porta);
	try{
		ssh.connect();
		if(ssh.isReady()) {
			for(String arquivo : arquivos){
				if(!ssh.upload(arquivo, dirDestino)){
					ssh.close();
					return false;
				}
			}
			ssh.close();
			return true;
		}
	} catch(Exception e){ e.printStackTrace(); }		
	return false;
}