0

刚刚确认 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)
4

1 回答 1

1

将 isImpcit 设置为 false。看起来服务器需要明确的 SSL 连接(即整个连接都是 SSL 加密的)。

于 2013-03-31T16:46:27.817 回答