0

Just confirmed that the FTPS server is indeed working using Filezilla. Quite puzzled with this exception.

Code

FTPSClient client = null;
        try {
            client = new FTPSClient(protocol, isImpicit);
        } catch (NoSuchAlgorithmException e1) {
            // TODO Auto-generated catch block
            Logger.debug(e1);
            e1.printStackTrace();
        }
        client.setDataTimeout(timeoutInMillis);
        //client.addProtocolCommandListener(new PrintCommandListener(new  PrintWriter(System.out)));

        System.out.println("################ Connecting to Server ################################");

        try
        {
            int reply;
            System.out.println("################ Connect Call ################################");
            client.connect(ftpServer, ftpPort);

            client.login(username, password);

            System.out.println("################ Login Success ################################");

            //client.setFileType(FTP.BINARY_FILE_TYPE);
            client.setFileType(FTP.NON_PRINT_TEXT_FORMAT);
            client.execPBSZ(0);  // Set protection buffer size
            client.execPROT("P"); // Set data channel protection to private
            client.enterLocalPassiveMode();

            System.out.println("Connected to " + server + ".");
            reply = client.getReplyCode();

            if (!FTPReply.isPositiveCompletion(reply))
            {
                client.disconnect();
                System.err.println("FTP server refused connection.");
                System.exit(1);
            }

            client.listFiles();
            //boolean retrieved = client.retrieveFile(remoteFile, new FileOutputStream(localFile));
        }
        catch (Exception e)
        {
            if (client.isConnected())
            {
                try
                {
                    client.disconnect();
                }
                catch (IOException ex)
                {
                    ex.printStackTrace();
                }
            }
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            return client;
        }
        finally
        {
            //client.disconnect();
            try {
                client.logout();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                Logger.debug(e);
                e.printStackTrace();
            }
            System.out.println("# client disconnected");
        }
        return client;

Stacktrace

################ Connecting to Server ################################
################ Connect Call ################################
Could not connect to server.
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
    at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(FTPSClient.java:240)
    at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:166)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:178)
    at myFtpService.getFtpConnection(myFtpService.java:61)
user207421
  • 305,947
  • 44
  • 307
  • 483
bouncingHippo
  • 5,940
  • 21
  • 67
  • 107
  • The exception suggests you are talking to a plaintext server, or at least some thing that isn't a straight SSL server. – user207421 Mar 25 '13 at 22:24

1 Answers1

1

set isImpicit to false. Looks like the server expects explicit SSL connectivity (i.e. entire connection to be SSL encrypted).

EaZ
  • 11
  • 1