Example usage for org.apache.commons.net.ftp FTPClient FTPClient

List of usage examples for org.apache.commons.net.ftp FTPClient FTPClient

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPClient FTPClient.

Prototype

public FTPClient() 

Source Link

Document

Default FTPClient constructor.

Usage

From source file:s32a.Server.Startup.FTPHandler.java

/**
 * Unregisters the server//w ww  .j a  v a 2s .c  om
 * @param serverInfo The serverinfo of the server
 */
void unRegisterServer(ServerInfo serverInfo) {
    FTPClient client = null;

    if (SSL) {
        client = new FTPSClient(false);
    } else {
        client = new FTPClient();
    }

    try {
        System.out.println("connecting");
        client.connect(ftpServer);
        if (!client.login(username, password)) {
            return;
        }

        boolean success = client.deleteFile(this.ftpRefLocation);
        System.out.println("dropped remote reference to file: " + success);
        client.logout();

    } catch (IOException ex) {
        showDialog("Error", "FTP: unRegisterServer IOException: " + ex.getMessage());
        //            System.out.println("IOException: " + ex.getMessage());
        //            ex.printStackTrace();
    } catch (Exception ex) {
        showDialog("Error", "FTP: CheckLogin Exception: " + ex.getMessage());
        //System.out.println("exception caught: " + ex.getMessage());
    } finally {
        try {
            client.disconnect();
        } catch (IOException e) {
            //e.printStackTrace();
        }
    }
}

From source file:savant.thousandgenomes.FTPBrowser.java

private FTPClient getFTPClient() throws IOException {
    if (ftp == null) {
        ftp = new FTPClient();
        ftp.connect(host, port);//from ww w .  jav a2 s . c  o m
        ftp.login(user, password);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();
        //            ftp.setSoTimeout(SOCKET_TIMEOUT);
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new IOException(String.format("FTP server refused connection (code %d).", reply));
        }
    }

    return ftp;
}

From source file:scannerapplication.scannerapps.java

/**
 * Creates new form scannerapps//from   www  .j a va 2s . c  o  m
 */
public scannerapps() {
    initComponents();
    localhost = jTextField1.getText();
    username = jTextField2.getText();
    password = jTextField3.getText();

    jList1.addFocusListener(this);
    jTextField1.addFocusListener(this);
    jTextField2.addFocusListener(this);
    jTextField3.addFocusListener(this);

    jButton1.addActionListener(this);
    jButton2.addActionListener(this);
    jButton3.addActionListener(this);
    jButton4.addActionListener(this);

    jButton3.setEnabled(false);

    File filename = new File("./");
    String currentPath = filename.getAbsolutePath();
    currentPath = currentPath.substring(0, currentPath.length() - 2);
    uploadDirectory = currentPath;

    Vector holder = new Vector();
    for (File fileEntry : filename.listFiles()) {
        if (!fileEntry.isDirectory()) {
            holder.add(fileEntry.getName());
            System.out.println(fileEntry.getName());
        }
    }
    jList1.setListData(holder);

    ftp = new FTPClient();
    scanner = Scanner.getDevice();
}

From source file:se.natusoft.maven.plugin.ftp.FTPMojo.java

/**
 * Executes the mojo.//from   w  ww .  jav a 2  s.c o m
 *
 * @throws MojoExecutionException
 */
public void execute() throws MojoExecutionException {
    FTPClient ftpClient = new FTPClient();
    try {
        ftpClient.connect(this.targetHost, this.targetPort);
        if (!ftpClient.login(this.userName, this.password)) {
            throw new MojoExecutionException("Failed to login user '" + this.userName + "'!");
        }
        this.getLog()
                .info("FTP: Connected to '" + this.targetHost + ":" + this.targetPort + "':" + this.targetPath);

        ftpClient.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE);
        ftpClient.setBufferSize(1024 * 60);

        SourcePaths sourcePaths = new SourcePaths(new File(this.baseDir), this.files);
        this.getLog().info("Files to upload: " + sourcePaths.getSourceFiles().size());

        int fileNo = 0;

        for (File transferFile : sourcePaths.getSourceFiles()) {
            String relPath = this.targetPath
                    + transferFile.getParentFile().getAbsolutePath().substring(this.baseDir.length());

            boolean havePath = ftpClient.changeWorkingDirectory(relPath);
            if (!havePath) {
                if (!mkdir(ftpClient, relPath)) {
                    throw new MojoExecutionException("Failed to create directory '" + relPath + "'!");
                }
                if (!ftpClient.changeWorkingDirectory(relPath)) {
                    throw new MojoExecutionException(
                            "Failed to change to '" + relPath + "' after its been created OK!");
                }
            }

            FileInputStream sendFileStream = new FileInputStream(transferFile);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.storeFile(transferFile.getName(), sendFileStream);
            sendFileStream.close();
            this.getLog().info(
                    "Transferred [" + ++fileNo + "]: " + relPath + File.separator + transferFile.getName());
        }
        this.getLog().info("All files transferred!");
    } catch (IOException ioe) {
        throw new MojoExecutionException(ioe.getMessage(), ioe);
    } finally {
        try {
            ftpClient.disconnect();
        } catch (IOException ioe) {
            this.getLog().error("Failed to disconnect from FTP site! [" + ioe.getMessage() + "]", ioe);
        }
    }
}

From source file:se.vgregion.webbisar.helpers.FileHandler.java

private FTPClient connect() throws FTPException {
    try {//from w  w  w.j  av  a2s.c  o  m
        FTPClient ftp = new FTPClient();
        ftp.connect(host, port);
        int reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            System.err.println("FTP server refused connection.");
        }
        ftp.login(userName, password);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        return ftp;
    } catch (SocketException e) {
        throw new FTPException("Failed to connect to server", e);
    } catch (IOException e) {
        throw new FTPException("Failed to connect to server", e);
    }
}

From source file:sge.servlet.IndicadorApoyo.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    IndicadorService is;//from ww  w  .  j ava  2s  . c  o m
    ReporteService rs;
    int opt = 0;
    int k = 0;
    System.out.println("------------ INDICADOR CONTROLADOR --------");
    if (request.getParameter("nro_indicador") != null) {
        k = Integer.parseInt(
                request.getParameter("nro_indicador") == null ? "" : request.getParameter("nro_indicador"));
        opt = Integer.parseInt(
                request.getParameter("opt" + k + "") == null ? "" : request.getParameter("opt" + k + ""));
    } else {
        if (request.getParameter("nro_indicador_1") != null) {
            k = Integer.parseInt(request.getParameter("nro_indicador_1") == null ? ""
                    : request.getParameter("nro_indicador_1"));
            opt = Integer.parseInt(
                    request.getParameter("opt" + k + "") == null ? "" : request.getParameter("opt" + k + ""));
        } else {
            if (request.getParameter("nro_indicador_2") != null) {
                k = Integer.parseInt(request.getParameter("nro_indicador_2") == null ? ""
                        : request.getParameter("nro_indicador_2"));
                opt = Integer.parseInt(request.getParameter("opt" + k + "") == null ? ""
                        : request.getParameter("opt" + k + ""));
            } else {
                opt = Integer.parseInt(request.getParameter("opt") == null ? "" : request.getParameter("opt"));
            }
        }
    }
    System.out.println("------------ opt -------- : " + opt);
    try {
        /*
         * TODO output your page here. You may use following sample code.
         */
        switch (opt) {
        case 1: {
            is = new IndicadorService();
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            response.sendRedirect(INDEXCOORDINADOREAP);
            break;
        }
        case 2: {
            is = new IndicadorService();
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("nro", null);
            request.getSession().setAttribute("eje", null);
            request.getSession().setAttribute("indicador", null);
            request.getSession().setAttribute("listar_indicador", null);
            String periodoVigente = (String) request.getParameter("idperiodometa") == null ? ""
                    : request.getParameter("idperiodometa");
            System.out.println("Holas:" + periodoVigente);
            response.sendRedirect(LIST_INDICADOR + "?periodoVigente=" + periodoVigente);
            break;
        }
        case 3: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                      
            is = new IndicadorService();
            is.insertarMeta(request);
            String nombre = request.getParameter("valor") == null ? "" : request.getParameter("valor");
            if (nombre == "") {
                request.getSession().setAttribute("listar_indicador", is.listaIndicador(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            } else {
                request.getSession().setAttribute("listar_indicador", is.listaIndicadorBuscar(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            }
            response.sendRedirect(LIST_INDICADOR);

            break;
        }
        case 4: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                      
            is = new IndicadorService();
            is.actualizarMeta(request);
            request.getSession().setAttribute("listar_indicador", is.listaIndicador(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(LIST_INDICADOR);
            break;
        }
        case 5: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                      
            is = new IndicadorService();
            int var = Integer.parseInt(request.getParameter("nro_indicador_4") == null ? ""
                    : request.getParameter("nro_indicador_4"));
            int idmeta = Integer.parseInt(request.getParameter("idmeta" + var + "") == null ? ""
                    : request.getParameter("idmeta" + var + ""));
            int idavancevalida = Integer.parseInt(request.getParameter("idavancevalida" + var + "") == null ? ""
                    : request.getParameter("idavancevalida" + var + ""));
            dirUploadFiles = getServletContext()
                    .getRealPath(getServletContext().getInitParameter("dirUploadFilesF"));
            if (ServletFileUpload.isMultipartContent(request)) {
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(new Long(getServletContext().getInitParameter("maxFileSize")).longValue()); // 1024 x 300 = 307200 bytes = 300 Kb       
                List listUploadFiles = null;
                FileItem item = null;
                try {
                    listUploadFiles = upload.parseRequest(request);
                    Calendar ahora = Calendar.getInstance();
                    int dia = ahora.get(Calendar.DAY_OF_MONTH); //dia del mes
                    int mes = ahora.get(Calendar.MONTH); //mes, de 0 a 11
                    int anio = ahora.get(Calendar.YEAR); //ao
                    int hora24 = ahora.get(Calendar.HOUR_OF_DAY); //hora en formato 24hs
                    int minutos = ahora.get(Calendar.MINUTE);
                    int segundos = ahora.get(Calendar.SECOND);
                    int milisegundos = ahora.get(Calendar.MILLISECOND);
                    Iterator it = listUploadFiles.iterator();
                    while (it.hasNext()) {
                        item = (FileItem) it.next();
                        if (!item.isFormField()) {
                            if (item.getSize() > 0) {
                                System.out.println(" Name ->" + item.getName());

                                String filenameI = "X";
                                filenameI = is.nombreArchivoDenominacion(idmeta);
                                String evidencia = item.getName();
                                String url = filenameI + "-" + dia + "." + mes + "." + anio + "-" + hora24 + "."
                                        + minutos + "." + segundos + "." + milisegundos
                                        + (item.getName().substring(item.getName().lastIndexOf(".")));

                                String type = item.getContentType();
                                long tamanio = item.getSize();
                                String tipo = url.substring(url.lastIndexOf("."));
                                File archivo = new File(dirUploadFiles, url);
                                item.write(archivo);

                                // Subir al FTP Files

                                ftp = new FTPClient();
                                ftp.addProtocolCommandListener(
                                        new PrintCommandListener(new PrintWriter(System.out)));
                                int reply;
                                ftp.connect("192.168.13.38");
                                reply = ftp.getReplyCode();
                                if (!FTPReply.isPositiveCompletion(reply)) {
                                    ftp.disconnect();
                                    throw new Exception("Exception in connecting to FTP Server");
                                }
                                ftp.login("sgew1", "escritura");
                                ftp.setFileType(FTP.BINARY_FILE_TYPE);
                                ftp.enterLocalPassiveMode();
                                FileDirectori fd = new FileDirectori();
                                String directorioX = fd.directorioFilial(Integer.parseInt(idFilialPri));
                                try (InputStream input = new FileInputStream(archivo)) {
                                    this.ftp.storeFile(directorioX + url, input);

                                }
                                if (this.ftp.isConnected()) {
                                    try {
                                        this.ftp.logout();
                                        this.ftp.disconnect();
                                    } catch (IOException f) {
                                        // do nothing as file is already saved to server
                                    }
                                }

                                // Fin FTP        
                                is = new IndicadorService();
                                if (archivo.exists()) {
                                    is.insertarEvidencia(evidencia, tipo, url, idavancevalida,
                                            Integer.parseInt(idUsuarioPri));
                                    System.out.println(" Guardado->" + archivo.getAbsolutePath());
                                    SeguimientoService ss;
                                    ss = new SeguimientoService();
                                    if (idavancevalida != 0) {
                                        ss.actulizarUserRespEstado(Integer.parseInt(idUsuarioPri),
                                                idavancevalida);
                                    }
                                } else {
                                    System.out.println("FALLO AL GUARDAR. NO EXISTE "
                                            + archivo.getAbsolutePath() + "</p>");
                                }
                            }
                        }
                    }
                } catch (FileUploadException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("eje", is.Eje(request));
            request.getSession().setAttribute("listar_indicador", is.listaIndicadorEje(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            request.getSession().setAttribute("listaEvidencia", is.ListaEvidenciaMeta(request));
            request.getSession().setAttribute("variable", is.nroVariableEvidencia(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMeta(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicadorEvidencia(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(EVIDENCIA);
            break;
        }

        case 6: {
            is = new IndicadorService();
            is.eliminarEvidenciaMeta(request);
            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 7: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                      
            is = new IndicadorService();
            request.getSession().setAttribute("nro", is.nroMeta(request));
            request.getSession().setAttribute("avanceMeta", is.avanceMeta(request));
            String nombre = request.getParameter("valor") == null ? "" : request.getParameter("valor");
            if (nombre == "") {
                request.getSession().setAttribute("listar_indicador", is.listaIndicador(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            } else {
                request.getSession().setAttribute("listar_indicador", is.listaIndicadorBuscar(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            }

            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 8: {
            request.getSession().setAttribute("idperiodometa", null);
            request.getSession().setAttribute("eje", null);
            is = new IndicadorService();
            sge.modelo.Usuario w = null;
            w = (sge.modelo.Usuario) request.getSession().getAttribute("listaPerfilUsuario");
            int idEjeEstrategicoX = w.getIdejeestrategico();
            System.out.println("Verrrrrr: " + idEjeEstrategicoX);
            request.getSession().setAttribute("listar_eje", is.listaEjeIndividual(idEjeEstrategicoX));
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            request.getSession().setAttribute("listar_indicador", null);
            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 9: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                      
            is = new IndicadorService();
            is.insertarAvance(request, idUsuarioPri);
            String nombre = request.getParameter("valor") == null ? "" : request.getParameter("valor");
            if (nombre == "") {
                request.getSession().setAttribute("listar_indicador", is.listaIndicador(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            } else {
                request.getSession().setAttribute("listar_indicador", is.listaIndicadorBuscar(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            }
            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 10: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                      
            is = new IndicadorService();
            is.actualizarAvance(request);

            request.getSession().setAttribute("listar_indicador", is.listaIndicador(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 11: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          
            is = new IndicadorService();
            is.buscar(request);
            request.getSession().setAttribute("eje", is.Eje(request));
            //request.getSession().setAttribute("eje", is.ejeEap(request,is.estadometa(request),is.estadoavance(request),Integer.parseInt(idFilialPri)));
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("listar_indicador", is.listaIndicadorBuscar(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            request.getSession().setAttribute("nro", null);
            request.getSession().setAttribute("nroestindicador", is.nroIndicador(request));
            request.getSession().setAttribute("indicador", is.nombreIndicador(request));
            response.sendRedirect(LIST_INDICADOR + "?valor=" + is.nombreIndicador(request));
            break;
        }

        case 12: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session   
            int idpm = Integer.parseInt(request.getParameter("idperiodometa") == null ? "0"
                    : request.getParameter("idperiodometa"));
            int idfi = Integer.parseInt(
                    request.getParameter("idfilial") == null ? "0" : request.getParameter("idfilial"));
            int idfa = Integer.parseInt(request.getParameter("idfilialfacultad") == null ? "0"
                    : request.getParameter("idfilialfacultad"));
            int idea = Integer.parseInt(request.getParameter("ideapfacultad") == null ? "0"
                    : request.getParameter("ideapfacultad"));
            is = new IndicadorService();
            request.getSession().setAttribute("estadoPOA", is.estadoPoa(idpm, idfi, idfa, idea));

            is = new IndicadorService();
            request.getSession().setAttribute("listaActividadIndicador", is.ListaActividadIndicador(request));
            request.getSession().setAttribute("listaActividad", is.ListaActividadMeta(request));
            request.getSession().setAttribute("variable", is.nroVariable(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMeta(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicador(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            rs = new ReporteService();
            request.getSession().setAttribute("sesionNivelFinan", rs.reporteNivelFinanciero());
            response.sendRedirect(POA);

            break;
        }

        case 13: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                        
            is = new IndicadorService();
            is.insertarActividad(request);
            request.getSession().setAttribute("variable", is.nroVariable(request));
            request.getSession().setAttribute("listaActividad", is.ListaActividadMeta(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMeta(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicador(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(POA);

            break;
        }
        // Consolidado-----         
        case 14: {
            is = new IndicadorService();
            OrganizacionService org = new OrganizacionService();

            // --------------------- SET SESSIONES CONSOLIDADOS    

            String idfilial = (String) request.getSession().getAttribute("IDFilialFsession");
            int idfilialfacultad = Integer.parseInt(request.getParameter("idfilialfacultad") == null ? ""
                    : request.getParameter("idfilialfacultad"));
            if (request.getParameter("idfilial") == null) {
                request.getSession().setAttribute("sessionFilial", org.getFilialId(Integer.parseInt(idfilial)));
            } else {
                int idfilial1 = Integer.parseInt(
                        request.getParameter("idfilial") == null ? "" : request.getParameter("idfilial"));
                request.getSession().setAttribute("sessionFilial", org.getFilialId(idfilial1));
            }

            request.getSession().setAttribute("sessionFacultad", org.getFilialFacultadId(idfilialfacultad));

            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            response.sendRedirect(INDEXCONSOLIDADOS);
            break;
        }

        case 15: {
            is = new IndicadorService();
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("listaEapConsolidado", is.listaEapConsolidado(request));
            response.sendRedirect(CONSOLIDADOEAP);
            break;
        }

        case 16: {

            request.getSession().setAttribute("idperiodometa", null);
            request.getSession().setAttribute("eje", null);
            is = new IndicadorService();
            sge.modelo.Usuario w = null;
            w = (sge.modelo.Usuario) request.getSession().getAttribute("listaPerfilUsuario");
            int idEjeEstrategicoX = w.getIdejeestrategico();
            request.getSession().setAttribute("listar_eje", is.listaEjeIndividual(idEjeEstrategicoX));
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("listaFacultadConsolidado", null);
            request.getSession().setAttribute("listaFilialConsolidado", null);

            response.sendRedirect(CONSOLIDADOFACULTAD);
            break;
        }

        case 17: {
            request.getSession().setAttribute("idperiodometa", null);
            request.getSession().setAttribute("eje", null);
            is = new IndicadorService();
            sge.modelo.Usuario w = null;
            w = (sge.modelo.Usuario) request.getSession().getAttribute("listaPerfilUsuario");
            int idEjeEstrategicoX = w.getIdejeestrategico();
            request.getSession().setAttribute("listar_eje", is.listaEjeIndividual(idEjeEstrategicoX));
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("listaFilialConsolidado", null);
            response.sendRedirect(CONSOLIDADOFILIAL);
            break;
        }

        //Consolidado----------------------------

        // Inicio coordnador EAP           
        case 18: {
            GestionEstrategicoService ges = new GestionEstrategicoService();
            List listarPoliticaUpeu = ges.Listar_Politica_Upeu();
            request.getSession().setAttribute("listar_politica_upeu", listarPoliticaUpeu);
            response.sendRedirect(POLITICAS);
            break;
        }

        case 19: {
            is = new IndicadorService();
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            sge.modelo.Usuario w = null;
            w = (sge.modelo.Usuario) request.getSession().getAttribute("listaPerfilUsuario");
            int idEjeEstrategicoX = w.getIdejeestrategico();
            request.getSession().setAttribute("listar_eje", is.listaEjeIndividual(idEjeEstrategicoX));
            response.sendRedirect(EJES);
            break;
        }

        case 20: {
            is = new IndicadorService();
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            response.sendRedirect(ESTRATEGIAS);
            break;
        }

        case 21: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          

            //        //Inicio Conexion        
            //                try {
            //                FTPClient ftp = null;                
            //                ftp = new FTPClient();
            //                ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
            //                int reply;
            //                ftp.connect("192.168.13.38");
            //                reply = ftp.getReplyCode();
            //                if (!FTPReply.isPositiveCompletion(reply)) {
            //                    ftp.disconnect();
            //                     throw new Exception("Exception in connecting to FTP Server");
            //                }
            //                ftp.login("tisge", "wmtisge:$0114");
            //                ftp.setFileType(FTP.BINARY_FILE_TYPE);
            //                ftp.enterLocalPassiveMode();                             
            //                } catch (Exception e) {
            //                }
            //        
            //        //End Conexion                    
            is = new IndicadorService();
            int nr = Integer.parseInt(request.getParameter("nro_indicador_4"));

            request.getSession().setAttribute("idavanceDmp", request.getParameter("idavancevalida" + nr + ""));
            request.getSession().setAttribute("condicionDmp", request.getParameter("condicion" + nr + ""));

            request.getSession().setAttribute("listaEvidencia", is.ListaEvidenciaMeta(request));
            request.getSession().setAttribute("variable", is.nroVariableEvidencia(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMeta(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicadorEvidencia(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(EVIDENCIA);
            break;

        }

        case 22: {
            is = new IndicadorService();
            request.getSession().setAttribute("eje", is.ejeFacultad(request));
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("listaFacultadConsolidado",
                    is.listaIndicadorFacultadBuscar(request));
            response.sendRedirect(CONSOLIDADOFACULTAD);

            break;
        }

        case 23: {
            is = new IndicadorService();
            request.getSession().setAttribute("eje", is.ejeFilial(request));
            request.getSession().setAttribute("listar_periodo_meta", is.listaPeriodoMeta(request));
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("listaFilialConsolidado", is.listaIndicadorFilialBuscar(request));
            response.sendRedirect(CONSOLIDADOFILIAL);
            break;
        }

        // Inicio coordnador Eje EAP        
        case 24: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          
            is = new IndicadorService();
            is.buscar(request);
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("eje", is.Eje(request));
            request.getSession().setAttribute("cicloAcademicoActivoSess", is.cicloActivo());
            request.getSession().setAttribute("nro", null);
            request.getSession().setAttribute("nroestindicador", is.nroIndicador(request));

            String nombre = request.getParameter("valor") == null ? "" : request.getParameter("valor");
            if (nombre == "") {
                request.getSession().setAttribute("listar_indicador", is.listaIndicadorEje(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            } else {
                request.getSession().setAttribute("listar_indicador", is.listaIndicadorBuscar(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            }
            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 25: {
            is = new IndicadorService();
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("eje", is.Eje(request));
            request.getSession().setAttribute("listaFacultadConsolidado",
                    is.listaIndicadorFacultadEje(request));
            response.sendRedirect(CONSOLIDADOFACULTAD);
            break;
        }

        case 26: {
            is = new IndicadorService();
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("eje", is.Eje(request));
            request.getSession().setAttribute("listaFilialConsolidado", is.listaIndicadorFilialEje(request));
            response.sendRedirect(CONSOLIDADOFILIAL);
            break;
        }

        case 27: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          
            is = new IndicadorService();
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));

            request.getSession().setAttribute("nro", null);
            request.getSession().setAttribute("eje", null);

            String nombre = request.getParameter("valor") == null ? "" : request.getParameter("valor");
            if (nombre == "") {
                request.getSession().setAttribute("listar_indicador", is.listaIndicador(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            } else {
                request.getSession().setAttribute("listar_indicador", is.listaIndicadorBuscar(request,
                        is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            }

            response.sendRedirect(LIST_INDICADOR);
            break;
        }

        case 28: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          
            is = new IndicadorService();
            is.EliminarActividadMeta(request);
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("eje", is.Eje(request));
            request.getSession().setAttribute("listar_indicador", is.listaIndicadorEje(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            request.getSession().setAttribute("nro", null);
            request.getSession().setAttribute("variable", is.nroVariable(request));
            request.getSession().setAttribute("listaActividad", is.ListaActividadMeta(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMeta(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicador(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(POA);

            break;
        }

        case 29: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          
            is = new IndicadorService();
            is.EliminarEvidencia(request);
            request.getSession().setAttribute("idperiodometa", is.idPeriodoMeta(request));
            request.getSession().setAttribute("eje", is.Eje(request));
            request.getSession().setAttribute("listar_indicador", is.listaIndicadorEje(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            request.getSession().setAttribute("listaEvidencia", is.ListaEvidenciaMeta(request));
            request.getSession().setAttribute("variable", is.nroVariableEvidencia(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMeta(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicadorEvidencia(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));
            response.sendRedirect(EVIDENCIA);

            break;
        }

        case 30: {
            //Inicio Session
            principalValorSession(request);
            //Fin Session                          
            is = new IndicadorService();
            is = new IndicadorService();
            is.actualizarActividad(request);
            request.getSession().setAttribute("listaActividadIndicador", is.ListaActividadIndicadorAx(request));
            request.getSession().setAttribute("listaActividad", is.ListaActividadMetaAx(request));
            request.getSession().setAttribute("variable", is.nroVariableAx(request));
            request.getSession().setAttribute("periodoMeta", is.periodoMetaAx(request));
            request.getSession().setAttribute("estrategiaIndicador", is.estrategiaIndicadorAx(request,
                    is.estadometa(request), is.estadoavance(request), Integer.parseInt(idFilialPri)));

            response.sendRedirect(POA);

            break;
        }

        case 31: {
            int idfilial = Integer.parseInt(
                    request.getParameter("idfilial") == null ? "0" : request.getParameter("idfilial"));
            int idtipoarea = Integer.parseInt(
                    request.getParameter("idtipoarea") == null ? "0" : request.getParameter("idtipoarea"));
            int rubro = Integer
                    .parseInt(request.getParameter("rubro") == null ? "0" : request.getParameter("rubro"));
            rs = new ReporteService();
            ArrayList lista = rs.reporteCuentaPorNivel(rubro, idfilial, idtipoarea);
            Iterator<Object> inter = lista.iterator();
            while (inter.hasNext()) {
                Map datos = (Map) inter.next();

                out.print(
                        "<option value='" + datos.get("idCuenta") + "'> " + datos.get("nombre") + " </option>");
            }
            break;
        }
        case 32: {
            int idPeriodo = Integer.parseInt(
                    request.getParameter("idPeriodo") == null ? "0" : request.getParameter("idPeriodo"));
            int idEapFacultad = Integer.parseInt(request.getParameter("idEapFacultad") == null ? "0"
                    : request.getParameter("idEapFacultad"));
            int subrubro = Integer.parseInt(
                    request.getParameter("subrubro") == null ? "0" : request.getParameter("subrubro"));
            rs = new ReporteService();
            double dato = 0;
            dato = rs.muestraSaldoDisponible(subrubro, idEapFacultad, idPeriodo);
            out.print("S/. " + dato);
            break;
        }
        case 33: {
            int idcuenta = Integer.parseInt(
                    request.getParameter("idcuenta") == null ? "0" : request.getParameter("idcuenta"));
            rs = new ReporteService();
            int dato = 0;
            dato = rs.idNivelfinanciero(idcuenta);
            out.print(dato);
            break;
        }
        }
    } finally {
        out.close();
    }

}

From source file:simplealbum.mvc.picture.impl.SenderFTP.java

public SenderFTP() throws IOException {
    ftpClient = new FTPClient();
    //        ftpClient.connect("192.168.1.68", 2151);
    ftpClient.connect("10.64.112.191", 2151);
    ftpClient.login("eam", "qaz");
    ftpClient.enterLocalPassiveMode();/*w  w w.  j a  va 2  s .  c  o  m*/
    ftpClient.setKeepAlive(true);
    logPath = "C:\\Users\\IBM_ADMIN\\Documents\\@EAM\\201506 SimpleCatalog\\SimpleCat\\build\\classes\\resource\\log.txt";
    listLog = new ArrayList(FileUtils.readLines(new File(logPath)));
    listConveyed = new ArrayList();
    Object[] toArray = FileUtils.readLines(new File(logPath)).toArray();
    Arrays.sort(toArray);
    System.out.println("Logdd " + logPath);

}

From source file:simplehttpdb.net.FTPHelper.java

/**
 * returns an FTP connection to the given server
 * if login fails null will be returned/*from  w  w w.j a va  2  s  .  co  m*/
 * @param ftpServer
 * @param ftpUser
 * @param ftpPass
 * @return
 * @throws SocketException
 * @throws IOException
 */
public FTPClient getFTPConnection(String ftpServer, String ftpUser, String ftpPass)
        throws SocketException, IOException {

    FTPClient ftp = new FTPClient();

    int reply;

    ftp.connect(ftpServer);
    Logger.getLogger(FTPHelper.class.getName()).log(Level.INFO,
            "Connected to " + ftpServer + " --> " + ftp.getReplyString());

    if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
        ftp.disconnect();
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "FTP server refused connection.");
        return null;
    }
    if (ftp.login(ftpUser, ftpPass)) {
        return ftp;
    } //else
    return null;
}

From source file:smilehouse.opensyncro.defaultcomponents.ftp.FTPDestination.java

public void take(String data, DestinationInfo info, MessageLogger logger)
        throws FailTransferException, AbortTransferException {

    FTPClient ftp = new FTPClient();

    try {/*  w  ww . ja  v a  2 s  .  c o m*/
        // -----------------
        // Try to connect...
        // -----------------
        String host = this.data.getAttribute(HOST_ATTR);
        int port = -1;
        String portStr = this.data.getAttribute(PORT_ATTR);
        if (portStr != null && portStr.length() > 0) {
            try {
                port = Integer.parseInt(portStr);
            } catch (NumberFormatException nfe) {
                logger.logMessage("Invalid value '" + portStr + "' for port.", this, MessageLogger.ERROR);
                PipeComponentUtils.failTransfer();
            }
        }
        int reply;

        try {
            if (port != -1) {
                ftp.connect(host, port);
            } else {
                ftp.connect(host);
            }
        } catch (SocketException e) {
            logger.logMessage("SocketException while connecting to host " + host + ", aborting", this,
                    MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        } catch (IOException e) {
            logger.logMessage("IOException while connecting to host " + host + ", aborting", this,
                    MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        }

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            try {
                ftp.disconnect();
            } catch (IOException e) {
                /**
                 * ftp.disconnect() is called only as additional clean-up here, so we choose to
                 * ignore possible exceptions
                 */
            }
            logger.logMessage("Couldn't connect to the FTP server: " + ftp.getReplyString(), this,
                    MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        }

        // -----------
        // Then log in
        // -----------

        try {
            if (!ftp.login(this.data.getAttribute(USER_ATTR), this.data.getAttribute(PASSWORD_ATTR))) {
                logger.logMessage("Could not log in, check your username and password settings.", this,
                        MessageLogger.ERROR);
                ftp.logout();

                PipeComponentUtils.failTransfer();
            }
        } catch (IOException e) {
            logger.logMessage("IOException while logging in to FTP server", this, MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        }

        // Use passive mode
        ftp.enterLocalPassiveMode();

        // -----------------
        // ASCII or binary ?
        // -----------------
        boolean fileTypeSetOk = false;

        try {
            switch (getFileType()) {
            case FILE_TYPE_ASCII:
                fileTypeSetOk = ftp.setFileType(FTP.ASCII_FILE_TYPE);
                break;
            case FILE_TYPE_BINARY:
                fileTypeSetOk = ftp.setFileType(FTP.BINARY_FILE_TYPE);
            }
            if (!fileTypeSetOk) {
                logger.logMessage("Could not set file type: " + ftp.getReplyString(), this,
                        MessageLogger.WARNING);
            }
        } catch (IOException e) {
            logger.logMessage("IOException while setting file transfer type parameter", this,
                    MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        }

        // -------------
        // Send the data
        // -------------
        String fileName = getFileName();
        logger.logMessage("Storing file: " + fileName, this, MessageLogger.DEBUG);
        String charSet = this.data.getAttribute(CHARSET_ATTR);
        if (charSet == null || charSet.length() == 0)
            charSet = DEFAULT_CHARSET;
        InputStream dataStream = null;
        try {
            dataStream = new ByteArrayInputStream(data.getBytes(charSet));
        } catch (UnsupportedEncodingException e1) {

            logger.logMessage(charSet + " charset not supported", this, MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        }
        try {
            if (!ftp.storeFile(fileName, dataStream)) {
                logger.logMessage("Could not store file '" + fileName + "': " + ftp.getReplyString(), this,
                        MessageLogger.ERROR);
                PipeComponentUtils.failTransfer();
            }
        } catch (IOException e) {
            logger.logMessage("IOException while uploading the file to FTP server", this, MessageLogger.ERROR);
            PipeComponentUtils.failTransfer();
        }
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
    }
}