Examples of FTPSClient


Examples of org.apache.commons.net.ftp.FTPSClient

            e.printStackTrace();
            status.setMessage("Error obtaining FTP host: " + e.getMessage());
            return status;
        }

        FTPSClient ftp = null;
        try {
            ftp = new FTPSClient(false, SSLContext.getDefault());

            System.out.println("Connecting to " + ftpHost + ":" + FTP_HOST_PORT);
            // ADDED connection retry logic
            int tryCount = 0;
            int maxTries = 5;
            boolean connectionSuccessful = false;
            do {
                try {
                    ftp.connect(ftpHost, FTP_HOST_PORT);
                    connectionSuccessful = true;
                } catch (Exception connectException) {
                    // wait 2 secs, then retry connection
                    try {
                        Thread.sleep((long) (Math.pow(2, (tryCount + 1)) * 1000));
                    } catch (InterruptedException e) {
                        // do nothing
                    }
                }
                if (++tryCount > maxTries) {
                    status.setMessage("FTP server refused connection (connection timeout).");
                    return status;
                }
            } while(!connectionSuccessful);
            // END connection retry logic

            SocrataConnectionInfo connectionInfo = userPrefs.getConnectionInfo();
            ftp.login(connectionInfo.getUser(), connectionInfo.getPassword());

            // verify connection was successful
            if(FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                System.out.println("ftp.setFileType(FTP.BINARY_FILE_TYPE)");
                ftp.setFileType(FTP.BINARY_FILE_TYPE);
                System.out.println("ftp.enterLocalPassiveMode()");
                ftp.enterLocalPassiveMode();

                // Set protection buffer size (what does this do??)
                //ftp.execPBSZ(0);
                // Set data channel protection to private
                System.out.println("ftp.execPROT(\"P\")");
                ftp.execPROT("P");

                String pathToDomainRoot = getPathToDomainRoot(ftp, connectionInfo);
                String pathToDatasetDir = pathToDomainRoot + "/" + datasetId;

                // if datasetId does not exist then create the directory
                System.out.println("ftp.listFiles(" + pathToDatasetDir + "/" + FTP_STATUS_FILENAME + ")");
                FTPFile[] checkDatasetDirExists = ftp.listFiles(pathToDatasetDir + "/" + FTP_STATUS_FILENAME);
                if(checkDatasetDirExists.length == 0) {
                    System.out.println("ftp.makeDirectory(" + pathToDatasetDir + ")");
                    boolean datasetDirCreated = ftp.makeDirectory(pathToDatasetDir);
                    if(!datasetDirCreated) {
                        closeFTPConnection(ftp);
                        status.setMessage("Error creating dataset ID directory at" +
                                " '" + pathToDatasetDir + "': " + ftp.getReplyString());
                        return status;
                    }
                }

                // set request Id for control file upload
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.