无法识别的SSL消息

时间:2013-03-25 18:09:33

标签: java ftps

刚刚确认FTPS服务器确实在使用Filezilla。对这个例外感到很困惑。

代码

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;

堆栈跟踪

################ 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)

1 个答案:

答案 0 :(得分:0)

将isImpicit设置为false。看起来服务器期望显式SSL连接(即整个连接是SSL加密的)。