public SocketProvider sendPortCommand(Command command, Reply commandReply)
            throws IOException, FtpWorkflowException, FtpIOException {
        
        setConnectionStatusLock(CSL_INDIRECT_CALL);
        setConnectionStatus(FTPConnection.BUSY);
        
        SocketProvider provider = null;
        
        if (getProxy() == null) {
            ServerSocket server = ServerSocketFactory.getDefault()
                .createServerSocket();
            InetSocketAddress isa = new InetSocketAddress(socketProvider.socket()
                .getLocalAddress(), 0);
        
            server.bind(isa);
            int port = server.getLocalPort();

            StringBuffer modifiedHost = new StringBuffer();
            modifiedHost.append(server.getInetAddress().getHostAddress().replace(
                '.', ','));
            modifiedHost.append(",");
            modifiedHost.append(port >> 8);
            modifiedHost.append(",");
            modifiedHost.append(port & 0x00ff);

            Command portCommand = new Command(Command.PORT, modifiedHost.toString());
            Reply portReply = sendCommand(portCommand);
            portReply.dumpReply();
            portReply.validate();
            commandReply.setLines(sendCommand(command).getLines());
            commandReply.dumpReply();
            commandReply.validate();
            provider = new SocketProvider(server.accept(), false,
                getDownloadBandwidth(), getUploadBandwidth());
        } else {
            InetSocketAddress portSocketAddress = new InetSocketAddress(getAddress().getAddress(), 0);
            Socket proxySocket = getProxy().bind(portSocketAddress);
            
            int port = getProxy().getBindAddress().getPort();

            StringBuffer modifiedHost = new StringBuffer();
            modifiedHost.append(getProxy().getProxyAddress().getAddress().getHostAddress().replace(
                '.', ','));
            modifiedHost.append(",");
            modifiedHost.append(port >> 8);
            modifiedHost.append(",");
            modifiedHost.append(port & 0x00ff);

            Command portCommand = new Command(Command.PORT, modifiedHost.toString());
            Reply portReply = sendCommand(portCommand);
            portReply.dumpReply();
            portReply.validate();
            commandReply.setLines(sendCommand(command).getLines());
            commandReply.dumpReply();
            commandReply.validate();
            
            provider = new SocketProvider(proxySocket, false, getDownloadBandwidth(), getUploadBandwidth());            
        }
            
        provider.socket().setReceiveBufferSize(65536);
        provider.socket().setSendBufferSize(65536);
        provider.setSSLMode(getConnectionType());
        if (connectionType == FTPConnection.AUTH_TLS_FTP_CONNECTION
                || connectionType == FTPConnection.AUTH_SSL_FTP_CONNECTION
                || connectionType == FTPConnection.IMPLICIT_SSL_WITH_CRYPTED_DATA_FTP_CONNECTION
                || connectionType == FTPConnection.IMPLICIT_TLS_WITH_CRYPTED_DATA_FTP_CONNECTION)
            provider.negotiate(this.getTrustManagers(),this.getKeyManagers());

        setConnectionStatus(FTPConnection.IDLE);
        setConnectionStatusLock(CSL_DIRECT_CALL);
        
        return provider;
    }