public void initEngineAndBuffers() throws NoSuchAlgorithmException,
            KeyStoreException, KeyManagementException, SSLException,
            IOException {
        if (mode == FTPConnection.AUTH_SSL_FTP_CONNECTION
                || mode == FTPConnection.IMPLICIT_SSL_FTP_CONNECTION)
            context = SSLContext.getInstance("SSL");
        else
            context = SSLContext.getInstance("TLS");
        if(trustManagers == null || trustManagers.length == 0)
            trustManagers = new TrustManager[] { new EasyX509TrustManager(
                null) };
        context.init(keyManagers, trustManagers, null);
        SSLSocketFactory sslFact = context.getSocketFactory();
        sslSocket = (SSLSocket) sslFact.createSocket(socket, socket
                .getInetAddress().getHostAddress(), socket.getPort(), true);
        if (maxUpload == FTPConnection.MAX_UPLOAD_BANDWIDTH
                || isControllConnection()) {
            out = sslSocket.getOutputStream();
        } else {
            out = new BandwidthControlledOutputStream(sslSocket
                    .getOutputStream(), maxUpload);
        }
        if (maxDownload == FTPConnection.MAX_DOWNLOAD_BANDWIDTH
                || isControllConnection()) {
            in = sslSocket.getInputStream();
        } else {
            in = new BandwidthControlledInputStream(sslSocket.getInputStream(),
                    maxDownload);
        }
        sslSocket.setEnableSessionCreation(true);
        sslSocket.setUseClientMode(true);
    }