public void open() throws IOException, ServerException {

        if (hasBeenOpened()) {
            throw new IOException("Attempt to open an already opened connection");
        }

        InetAddress                     allIPs[];

        //depending on constructor used, we may already have streams
        if (!haveStreams()) {
            boolean                     found = false;
            int                         i = 0;
            boolean                     firstPass = true;

            allIPs = InetAddress.getAllByName(host);

            while(!found)
            {
                try
                {
                    logger.debug("opening control channel to "
                        + allIPs[i] + " : " + port);
                    InetSocketAddress isa =
                        new InetSocketAddress(allIPs[i], port);

                    socket = new Socket();
                    socket.setSoTimeout(CoGProperties.getDefault().getSocketTimeout());
                    socket.connect(isa, CoGProperties.getDefault().getSocketTimeout());
                    found = true;
                }
                catch(IOException ioEx)
                {
                    logger.debug("failed connecting to  "
                        + allIPs[i] + " : " + port +":"+ioEx);
                    i++;
                    if(i == allIPs.length)
                    {
                        if(firstPass)
                        {
                            firstPass = false;
                            i = 0;
                        }
                        else
                        {
                            throw ioEx;
                        }
                    }
                }
            }

            String pv = System.getProperty("org.globus.ftp.IPNAME");
            if(pv != null)
            {
                host = socket.getInetAddress().getHostAddress();
            }
            else
            {
                host = socket.getInetAddress().getCanonicalHostName();
            }

            setInputStream(socket.getInputStream());
            setOutputStream(socket.getOutputStream());
        }

        readInitialReplies();

        hasBeenOpened = true;
    }
public void open ( ) throws IOException , ServerException { if ( hasBeenOpened ( ) ) { throw new IOException ( "Attempt to open an already opened connection" ) ; } InetAddress allIPs [ ] ; if ( ! haveStreams ( ) ) { boolean found = false ; int i = 0 ; boolean firstPass = true ; allIPs = InetAddress . getAllByName ( host ) ; while ( ! found ) { try { logger . debug ( "opening control channel to " + allIPs [ i ] + " : " + port ) ; InetSocketAddress isa = new InetSocketAddress ( allIPs [ i ] , port ) ; socket = new Socket ( ) ; socket . setSoTimeout ( CoGProperties . getDefault ( ) . getSocketTimeout ( ) ) ; socket . connect ( isa , CoGProperties . getDefault ( ) . getSocketTimeout ( ) ) ; found = true ; } catch ( IOException ioEx ) { logger . debug ( "failed connecting to  " + allIPs [ i ] + " : " + port + ":" + ioEx ) ; i ++ ; if ( i == allIPs . length ) { if ( firstPass ) { firstPass = false ; i = 0 ; } else { throw ioEx ; } } } } String pv = System . getProperty ( "org.globus.ftp.IPNAME" ) ; if ( pv != null ) { host = socket . getInetAddress ( ) . getHostAddress ( ) ; } else { host = socket . getInetAddress ( ) . getCanonicalHostName ( ) ; } setInputStream ( socket . getInputStream ( ) ) ; setOutputStream ( socket . getOutputStream ( ) ) ; } readInitialReplies ( ) ; hasBeenOpened = true ; }
opens the connection and returns after it is ready for communication.
Before returning, it intercepts the initial server reply(-ies),
and not positive, throws UnexpectedReplyCodeException.
After returning, there should be no more queued replies on the line.

Here's the sequence for connection establishment (rfc959):
<PRE>
120
220
220
421
</PRE>
@throws IOException on I/O error
@throws ServerException on negative or faulty server reply