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:it.greenvulcano.util.remotefs.ftp.FTPManager.java

/**
 * Create a new FTPSClient object//from  w w w .  ja v  a 2s  .c o  m
 * 
 */
protected FTPClient createFTPClient() throws RemoteManagerException {
    try {
        return new FTPClient();
    } catch (Exception exc) {
        throw new RemoteManagerException("Error instantiating FTPClient", exc);
    }
}

From source file:com.microsoft.intellij.forms.CreateWebSiteForm.java

private void copyWebConfigForCustom(WebSiteConfiguration config) throws AzureCmdException {
    if (config != null) {
        AzureManager manager = AzureManagerImpl.getManager(project);
        WebSitePublishSettings webSitePublishSettings = manager.getWebSitePublishSettings(
                config.getSubscriptionId(), config.getWebSpaceName(), config.getWebSiteName());
        // retrieve ftp publish profile
        WebSitePublishSettings.FTPPublishProfile ftpProfile = null;
        for (WebSitePublishSettings.PublishProfile pp : webSitePublishSettings.getPublishProfileList()) {
            if (pp instanceof WebSitePublishSettings.FTPPublishProfile) {
                ftpProfile = (WebSitePublishSettings.FTPPublishProfile) pp;
                break;
            }/*from  w  w w .  ja v a  2s  . com*/
        }

        if (ftpProfile != null) {
            FTPClient ftp = new FTPClient();
            try {
                URI uri = null;
                uri = new URI(ftpProfile.getPublishUrl());
                ftp.connect(uri.getHost());
                final int replyCode = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(replyCode)) {
                    ftp.disconnect();
                }
                if (!ftp.login(ftpProfile.getUserName(), ftpProfile.getPassword())) {
                    ftp.logout();
                }
                ftp.setFileType(FTP.BINARY_FILE_TYPE);
                if (ftpProfile.isFtpPassiveMode()) {
                    ftp.enterLocalPassiveMode();
                }
                ftp.deleteFile(ftpPath + message("configName"));
                String tmpPath = String.format("%s%s%s", System.getProperty("java.io.tmpdir"), File.separator,
                        message("configName"));
                File file = new File(tmpPath);
                if (file.exists()) {
                    file.delete();
                }

                WAEclipseHelperMethods.copyFile(WAHelper.getCustomJdkFile(message("configName")), tmpPath);
                String jdkFolderName = "";
                if (customJDKUser.isSelected()) {
                    String url = customUrl.getText();
                    jdkFolderName = url.substring(url.lastIndexOf("/") + 1, url.length());
                    jdkFolderName = jdkFolderName.substring(0, jdkFolderName.indexOf(".zip"));
                } else {
                    String cloudVal = WindowsAzureProjectManager
                            .getCloudValue((String) jdkNames.getSelectedItem(), AzurePlugin.cmpntFile);
                    jdkFolderName = cloudVal.substring(cloudVal.indexOf("\\") + 1, cloudVal.length());
                }
                String jdkPath = "%HOME%\\site\\wwwroot\\jdk\\" + jdkFolderName;
                String serverPath = "%programfiles(x86)%\\" + WAHelper
                        .generateServerFolderName(config.getJavaContainer(), config.getJavaContainerVersion());
                WebAppConfigOperations.prepareWebConfigForCustomJDKServer(tmpPath, jdkPath, serverPath);
                InputStream input = new FileInputStream(tmpPath);
                ftp.storeFile(ftpPath + message("configName"), input);
                cleanup(ftp);
                ftp.logout();
            } catch (Exception e) {
                AzurePlugin.log(e.getMessage(), e);
            } finally {
                if (ftp.isConnected()) {
                    try {
                        ftp.disconnect();
                    } catch (IOException ignored) {
                    }
                }
            }
        }
    }
}

From source file:GestoSAT.GestoSAT.java

public boolean actualizarConfiguracion(Vector<String> mySQL, Vector<String> confSeg, int iva, String logo)
        throws Exception {
    FileReader file;//from w  ww .  j av a2 s  . c o m
    try {
        this.iva = Math.abs(iva);

        BufferedImage image = null;
        byte[] imageByte;

        BASE64Decoder decoder = new BASE64Decoder();
        imageByte = decoder.decodeBuffer(logo.split(",")[1]);
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
        image = ImageIO.read(bis);
        bis.close();

        // write the image to a file
        File outputfile = new File("logo");
        String formato = logo.split("/")[1].split(";")[0];
        ImageIO.write(image, formato, outputfile);

        // MySQL
        if (mySQL.elementAt(0).equals(this.mySQL.elementAt(0))) {
            if (!mySQL.elementAt(1).equals(this.mySQL.elementAt(1))
                    && !mySQL.elementAt(2).equals(this.mySQL.elementAt(2))
                    && (!mySQL.elementAt(3).equals(this.mySQL.elementAt(3))
                            || !mySQL.elementAt(0).equals(""))) {
                Class.forName("com.mysql.jdbc.Driver");
                this.con.close();
                this.con = DriverManager.getConnection("jdbc:mysql://" + mySQL.elementAt(0) + ":"
                        + Math.abs(Integer.parseInt(mySQL.elementAt(1))) + "/gestosat?user="
                        + mySQL.elementAt(2) + "&password=" + mySQL.elementAt(3));

                this.mySQL.set(0, mySQL.elementAt(0));
                this.mySQL.set(1, Math.abs(Integer.parseInt(mySQL.elementAt(1))) + "");
                this.mySQL.set(2, mySQL.elementAt(2));
                this.mySQL.set(3, mySQL.elementAt(3));
            }
        } else {
            // Comprobar que pass != ""
            Process pGet = Runtime.getRuntime()
                    .exec("mysqldump -u " + this.mySQL.elementAt(2) + " -p" + this.mySQL.elementAt(3) + " -h "
                            + this.mySQL.elementAt(0) + " -P " + this.mySQL.elementAt(1) + " gestosat");

            InputStream is = pGet.getInputStream();
            FileOutputStream fos = new FileOutputStream("backupGestoSAT.sql");
            byte[] bufferOut = new byte[1000];

            int leido = is.read(bufferOut);
            while (leido > 0) {
                fos.write(bufferOut, 0, leido);
                leido = is.read(bufferOut);
            }
            fos.close();

            Class.forName("com.mysql.jdbc.Driver");
            this.con.close();
            this.con = DriverManager.getConnection(
                    "jdbc:mysql://" + mySQL.elementAt(0) + ":" + Math.abs(Integer.parseInt(mySQL.elementAt(1)))
                            + "/gestosat?user=" + mySQL.elementAt(2) + "&password=" + mySQL.elementAt(3));

            this.mySQL.set(0, mySQL.elementAt(0));
            this.mySQL.set(1, Math.abs(Integer.parseInt(mySQL.elementAt(1))) + "");
            this.mySQL.set(2, mySQL.elementAt(2));
            this.mySQL.set(3, mySQL.elementAt(3));

            Process pPut = Runtime.getRuntime()
                    .exec("mysql -u " + mySQL.elementAt(2) + " -p" + mySQL.elementAt(3) + " -h "
                            + mySQL.elementAt(0) + " -P " + Math.abs(Integer.parseInt(mySQL.elementAt(1)))
                            + " gestosat");

            OutputStream os = pPut.getOutputStream();
            FileInputStream fis = new FileInputStream("backupGestoSAT.sql");
            byte[] bufferIn = new byte[1000];

            int escrito = fis.read(bufferIn);
            while (escrito > 0) {
                os.write(bufferIn, 0, leido);
                escrito = fis.read(bufferIn);
            }

            os.flush();
            os.close();
            fis.close();
        }

        // FTP

        FTPClient cliente = new FTPClient();
        if (!confSeg.elementAt(3).equals("")) {
            cliente.connect(confSeg.elementAt(0), Integer.parseInt(confSeg.elementAt(1)));

            if (cliente.login(confSeg.elementAt(2), confSeg.elementAt(3))) {
                cliente.setFileType(FTP.BINARY_FILE_TYPE);
                BufferedInputStream buffIn = new BufferedInputStream(new FileInputStream("backupGestoSAT.sql"));
                cliente.enterLocalPassiveMode();
                cliente.storeFile("backupGestoSAT.sql", buffIn);
                buffIn.close();
                cliente.logout();
                cliente.disconnect();

                this.confSeg = confSeg;
            } else
                return false;
        }

        File archConf = new File("confGestoSAT");
        BufferedWriter bw = new BufferedWriter(new FileWriter(archConf));
        bw.write(this.mySQL.elementAt(0) + ";" + Math.abs(Integer.parseInt(this.mySQL.elementAt(1))) + ";"
                + this.mySQL.elementAt(2) + ";" + this.mySQL.elementAt(3) + ";" + this.confSeg.elementAt(0)
                + ";" + Math.abs(Integer.parseInt(this.confSeg.elementAt(1))) + ";" + this.confSeg.elementAt(2)
                + ";" + this.confSeg.elementAt(3) + ";" + Math.abs(iva));
        bw.close();

        return true;
    } catch (Exception ex) {
        file = new FileReader("confGestoSAT");
        BufferedReader b = new BufferedReader(file);
        String cadena;
        cadena = b.readLine();
        String[] valores = cadena.split(";");

        this.mySQL.add(valores[0]);
        this.mySQL.add(Math.abs(Integer.parseInt(valores[1])) + "");
        this.mySQL.add(valores[2]);
        this.mySQL.add(valores[3]);
        con.close();
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager
                .getConnection("jdbc:mysql://" + this.mySQL.elementAt(0) + ":" + this.mySQL.elementAt(1)
                        + "/gestosat?user=" + this.mySQL.elementAt(2) + "&password=" + this.mySQL.elementAt(3));

        this.confSeg.add(valores[4]);
        this.confSeg.add(Math.abs(Integer.parseInt(valores[5])) + "");
        this.confSeg.add(valores[6]);
        this.confSeg.add(valores[7]);

        file.close();
        Logger.getLogger(GestoSAT.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:net.cbtltd.rest.interhome.A_Handler.java

/**
 * Checks modification date of file from svn with given date
 * @param fn - filename string//from w ww . ja v  a  2s .  c om
 * @param date - date to compare
 * @return true if file version is after selected date
 */
private boolean checkVersion(String fn, Date date) {
    //check version of svn file and last price database entry
    FTPClient ftpClient = new FTPClient();
    boolean newVersion = false;
    try {
        ftpClient.connect("ftp.interhome.com");
        ftpClient.login("ihxmlpartner", "S13oPjEu");
        Date priceModifDate = FTPService.getFileModificationDate(ftpClient, fn + ".zip");
        if (priceModifDate.after(date)) {
            newVersion = true;
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (ftpClient.isConnected()) {
            try {
                ftpClient.disconnect();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    return newVersion;
}

From source file:com.muslumyusuf.DBOperations.java

private boolean uploadToFTP(String username, String fileName, InputStream inputStream) {
    FTPClient client = new FTPClient();
    try {/*from  w ww. ja v  a2 s . c  om*/
        client.connect(Initialize.FTPClient());
        if (client.login(Initialize.FTPUsername(), Initialize.getPASSWORD())) {
            client.setDefaultTimeout(10000);
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            if (client.storeFile(Tags.SITE + username + "/" + fileName, inputStream)) {
                return true;
            }
        }
    } catch (IOException e) {
        Logger.getLogger(DBOperations.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        if (client.isConnected()) {
            try {
                client.logout();
                client.disconnect();
            } catch (IOException ex) {
                Logger.getLogger(DBOperations.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    return false;
}

From source file:com.hackengine_er.muslumyusuf.DBOperations.java

private boolean uploadToFTP(String username, String fileName, InputStream inputStream) {
    FTPClient client = new FTPClient();
    try {//from   w  w  w . j a  va  2  s. c o m
        client.connect(Configuration.FTPClient());
        if (client.login(Configuration.FTPUsername(), Configuration.getPASSWORD())) {
            client.setDefaultTimeout(10000);
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            if (client.storeFile(Tags.SITE + username + "-" + fileName, inputStream)) {
                return true;
            }
        }
    } catch (IOException e) {
        Logger.getLogger(DBOperations.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        if (client.isConnected()) {
            try {
                client.logout();
                client.disconnect();
            } catch (IOException ex) {
                Logger.getLogger(DBOperations.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    return false;
}

From source file:com.droid.app.fotobot.FotoBot.java

public boolean files_to_ftp(List<String> FTP_files) {
    String server;//w  w  w  .  j  av a 2 s  . co m
    int port;
    String user;
    String pass;

    String FTP_folder = "";

    if (FTP_server.contains("/")) {

        FTP_folder = FTP_server.substring(FTP_server.indexOf("/", 1));
        FTP_folder = FTP_folder.substring(1);

        server = FTP_server.substring(0, FTP_server.indexOf("/", 1));
    } else {
        server = FTP_server;
    }

    port = Integer.parseInt(FTP_port);
    user = FTP_username;
    pass = FTP_password;

    SendMessage("FTP user: " + "<br>" + user, MSG_PASS);
    SendMessage("FTP folder: " + "<br>" + FTP_folder, MSG_PASS);
    SendMessage("FTP server: " + "<br>" + server, MSG_PASS);

    FTPClient ftpClient = new FTPClient();

    try {
        int reply;

        ftpClient.connect(server, port);
        System.out.println("Connected to " + server + ".");
        System.out.print(ftpClient.getReplyString());
        reply = ftpClient.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftpClient.disconnect();
            System.err.println("FTP server refused connection.");
            SendMessage("FTP   ?", MSG_FAIL);
            return false;
        }
    } catch (Exception e) {
    }

    try {
        ftpClient.login(user, pass);
        ftpClient.enterLocalPassiveMode();
        if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            SendMessage(
                    " ?   FTP ?,      FTP  ?.",
                    MSG_FAIL);
            return false;
        }
    } catch (Exception e) {

    }

    // chdir

    if (FTP_folder.length() > 1) {
        try {
            ftpClient.changeWorkingDirectory(FTP_folder);

            if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                ftpClient.disconnect();
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.err.println("FTP chdir error");
                SendMessage(
                        "FTP  ?    <br>" + FTP_folder,
                        MSG_FAIL);
                return false;
            }

            SendMessage("FTP   <br>" + FTP_folder, MSG_PASS);
            System.out.println("Successfully changed working directory.");
        } catch (Exception e) {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            SendMessage("FTP  ?    <br>" + FTP_folder,
                    MSG_FAIL);
            System.out.println("Failed to change working directory.");
            return false;
        }
    }

    try {
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    } catch (Exception e) {
        SendMessage("FTP   BINARY_FILE_TYPE", MSG_FAIL);
        System.out.println("Failed to change to BINARY_FILE_TYPE.");
        return false;
    }

    // APPROACH #1: uploads first file using an InputStream

    for (String str : FTP_files) {
        File firstLocalFile = new File(str);

        String firstRemoteFile = firstLocalFile.getName();

        try {
            InputStream inputStream = new FileInputStream(firstLocalFile);

            SendMessage("? ", MSG_PASS);
            boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
            inputStream.close();

            if (done) {
                SendMessage(" " + "<br>" + str + "<br>" + " ", MSG_PASS);
            }
        } catch (IOException ex) {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            SendMessage(" ?  " + "<br>" + str + "<br>"
                    + ftpClient.getReplyCode() + "\n" + ftpClient.getReplyString() + "\n" + ex.getMessage()
                    + "<br>"
                    + "     FTP  ?.",
                    MSG_FAIL);
            ex.printStackTrace();
        }

    }

    try {
        if (ftpClient.isConnected()) {
            ftpClient.logout();
            ftpClient.disconnect();
            SendMessage("FTP ???? ", MSG_PASS);
            fbpause(h, 3);
            return true;
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        SendMessage("FTP ???? ", MSG_FAIL);
    }

    return false;

}

From source file:com.netpace.aims.controller.application.WapApplicationHelper.java

public static boolean wapFTPZipFile(File transferFile) throws AimsException {

    log.debug("wapFTPZipFile FTP Start. FileName: " + transferFile.getName());
    boolean loginStatus = false;
    boolean dirChanged = false;

    FileInputStream transferStream = null;
    FTPClient ftpClient = new FTPClient();

    ConfigEnvProperties envProperties = ConfigEnvProperties.getInstance();
    //ftp server config
    String ftpServerAddress = envProperties.getProperty("wap.images.ftp.server.address");
    String ftpUser = envProperties.getProperty("wap.images.ftp.user.name");
    String ftpPassword = envProperties.getProperty("wap.images.ftp.user.password");
    String ftpWorkingDirectory = envProperties.getProperty("wap.images.ftp.working.dir");

    //general exception for ftp transfer
    AimsException aimsException = new AimsException("Error");
    aimsException.addException(new AimsException("error.wap.app.ftp.transfer"));

    String errorMessage = "";

    boolean transfered = false;
    try {/*from   w  w  w  . ja  v  a 2 s.  co m*/
        ftpClient.connect(ftpServerAddress);
        loginStatus = ftpClient.login(ftpUser, ftpPassword);
        log.debug("Connection to server " + ftpServerAddress + " " + (loginStatus ? "success" : "failure"));
        if (loginStatus) {
            dirChanged = ftpClient.changeWorkingDirectory(ftpWorkingDirectory);
            log.debug("change remote directory to " + ftpWorkingDirectory + ": " + dirChanged);
            if (dirChanged) {
                transferStream = new FileInputStream(transferFile);
                ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
                transfered = ftpClient.storeFile(transferFile.getName(), transferStream);
                log.debug(transferFile.getName() + " transfered: " + transfered + " on server: "
                        + ftpServerAddress);
                if (!transfered) {
                    errorMessage = "File: " + transferFile.getName() + " not transfered to "
                            + (ftpServerAddress + "/" + ftpServerAddress);
                    System.out.println("Error in FTP Transfer: " + errorMessage);
                    sendFTPErrorMail(errorMessage);
                    throw aimsException;
                }
            } else {
                errorMessage = "Directory: " + ftpWorkingDirectory + " not found in " + ftpServerAddress;
                System.out.println("Error in FTP Transfer: " + errorMessage);
                sendFTPErrorMail(errorMessage);
                throw aimsException;
            }
        } //end loginstatus
        else {
            errorMessage = "FTP Authentication failed. \n\nServer: " + ftpServerAddress + "\nUserID: " + ftpUser
                    + "\nPassword: " + ftpPassword;
            System.out.println("Error in FTP Transfer: " + errorMessage);
            sendFTPErrorMail(errorMessage);
            throw aimsException;
        }
    } //end try
    catch (FileNotFoundException e) {
        System.out.println("Exception: " + transferFile.getName() + " not found in temp directory");
        e.printStackTrace();//zip file not found
        throw aimsException;
    } catch (IOException ioe) {
        System.out.println("Exception: Error in connection " + ftpServerAddress);
        ioe.printStackTrace();
        sendFTPErrorMail("Error in connection to : " + ftpServerAddress + "\n\n"
                + MiscUtils.getExceptionStackTraceInfo(ioe));
        throw aimsException;
    } finally {
        try {
            //close stream
            if (transferStream != null) {
                transferStream.close();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    //logout. Issues QUIT command
                    ftpClient.logout();
                } catch (IOException ioex) {
                    ioex.printStackTrace();
                } finally {
                    try {
                        //disconnect ftp session
                        ftpClient.disconnect();
                    } catch (IOException ioexc) {
                        ioexc.printStackTrace();
                    }
                }
            }
        }

    }
    log.debug("wapFTPZipFile FTP end. FileName: " + transferFile.getName() + "\t transfered: " + transfered);
    return transfered;
}

From source file:com.microsoft.tooling.msservices.helpers.azure.AzureManagerImpl.java

@Override
public void publishWebArchiveArtifact(@NotNull String subscriptionId, @NotNull String webSpaceName,
        @NotNull String webSiteName, @NotNull String artifactPath, @NotNull boolean isDeployRoot,
        @NotNull String artifactName) throws AzureCmdException {
    WebSitePublishSettings webSitePublishSettings = getWebSitePublishSettings(subscriptionId, webSpaceName,
            webSiteName);/*from  w ww  .  j a v  a 2  s  .co  m*/
    WebSitePublishSettings.FTPPublishProfile publishProfile = null;
    for (PublishProfile pp : webSitePublishSettings.getPublishProfileList()) {
        if (pp instanceof FTPPublishProfile) {
            publishProfile = (FTPPublishProfile) pp;
            break;
        }
    }

    if (publishProfile == null) {
        throw new AzureCmdException("Unable to retrieve FTP credentials to publish web site");
    }

    URI uri;

    try {
        uri = new URI(publishProfile.getPublishUrl());
    } catch (URISyntaxException e) {
        throw new AzureCmdException("Unable to parse FTP Publish Url information", e);
    }

    final FTPClient ftp = new FTPClient();

    try {
        ftp.connect(uri.getHost());
        final int replyCode = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(replyCode)) {
            ftp.disconnect();
            throw new AzureCmdException("Unable to connect to FTP server");
        }

        if (!ftp.login(publishProfile.getUserName(), publishProfile.getPassword())) {
            ftp.logout();
            throw new AzureCmdException("Unable to login to FTP server");
        }

        ftp.setFileType(FTP.BINARY_FILE_TYPE);

        if (publishProfile.isFtpPassiveMode()) {
            ftp.enterLocalPassiveMode();
        }

        String targetDir = getAbsolutePath(uri.getPath());
        targetDir += "/webapps";

        InputStream input = new FileInputStream(artifactPath);
        if (isDeployRoot) {
            ftp.storeFile(targetDir + "/ROOT.war", input);
        } else {
            ftp.storeFile(targetDir + "/" + artifactName + ".war", input);
        }
        input.close();
        ftp.logout();
    } catch (IOException e) {
        throw new AzureCmdException("Unable to connect to the FTP server", e);
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:ProtocolRunner.java

public static SocketClient getTCPClientInstance(int clientType) {
   switch(clientType) {
        case 0: { // is chargen
            if(charGenTCPClient == null) {
                charGenTCPClient = new CharGenTCPClient();
            }//ww  w.  jav  a 2  s .  c o m
            return charGenTCPClient;
        }
       case 1: { // is daytime 
           if(daytimeTCPClient == null) {
               daytimeTCPClient = new DaytimeTCPClient();
           }
           return daytimeTCPClient;
       }
       case 2: { // is echo
           if(echoTCPClient == null) {
               echoTCPClient = new EchoTCPClient();
           }
           return echoTCPClient;
       }
       case 3: { // is finger
           if(fingerClient == null) {
               fingerClient = new FingerClient();
           }
           return fingerClient;
       }
       case 4: { // is ftp
           if(ftpClient == null) {
               ftpClient = new FTPClient();
           }
           return ftpClient;
       }
       case 5: { // is nntp
           if(nntpClient == null) {
               nntpClient = new NNTPClient();
           }
           return nntpClient;
       }
       case 6: { // is pop3
           if(pop3Client == null) {
               pop3Client = new POP3Client();
           }
           return pop3Client;
       }
       case 7: { // is smtp
           if(smtpClient == null) {
               smtpClient = new SMTPClient();
           }
           return smtpClient;
       }
       case 8: { // is time
           if(timeTCPClient == null) {
               timeTCPClient = new TimeTCPClient();
           }
           return timeTCPClient;
       }
       case 9: { // is whois
           if(whoisClient == null) {
               whoisClient = new WhoisClient();
           }
           return whoisClient;
       }
    }
    return null;
}