Logo Search packages:      
Sourcecode: jftp version File versions  Download package

int net::sf::jftp::net::FtpConnection::login ( String  username,
String  password 
) [inline]

Connect to the server an log in.

Does also fire directory update and connection initialized event if successful or connection failed event if failed.

Parameters:
username The username
password The password
Returns:
WRONG_LOGIN_DATA, OFFLINE, GENERIC_FAILED or LOGIN_OK status code

Definition at line 232 of file FtpConnection.java.

References binary(), chdirNoRefresh(), connected, fireConnectionFailed(), fireConnectionInitialized(), fireDirectoryUpdate(), net::sf::jftp::net::FtpConstants::GENERIC_FAILED, getLine(), getOsType(), net::sf::jftp::net::JConnection::getReader(), host, in, net::sf::jftp::net::JConnection::isThere(), jcon, net::sf::jftp::net::FtpConstants::LOGIN_OK, net::sf::jftp::net::FtpConstants::OFFLINE, net::sf::jftp::net::FtpConstants::PASS, port, net::sf::jftp::net::JConnection::send(), system(), updatePWD(), net::sf::jftp::net::FtpConstants::USER, and net::sf::jftp::net::FtpConstants::WRONG_LOGIN_DATA.

    {
        this.username = username;
        this.password = password;

        int status = LOGIN_OK;

        if(msg)
        {
            Log.debug("Connecting to " + host);
        }

        jcon = new JConnection(host, port);

        if(jcon.isThere())
        {
            in = jcon.getReader();

            if(getLine(POSITIVE) == null)//FTP220_SERVICE_READY) == null)
            {
                ok = false;
                Log.debug("Server closed Connection, maybe too many users...");
                status = OFFLINE;
            }

            if(msg)
            {
                Log.debug("Connection established...");
            }

            jcon.send(USER + " " + username);

            if(!getLine(loginAck).startsWith(POSITIVE))//FTP230_LOGGED_IN))
            {
                jcon.send(PASS + " " + password);

                if(success(POSITIVE))//FTP230_LOGGED_IN))
                {
                    if(msg)
                    {
                        Log.debug("Logged in...");
                    }
                }
                else
                {
                    Log.debug("Wrong password!");
                    ok = false;
                    status = WRONG_LOGIN_DATA;
                }
            }

            // end if(jcon)...
        }
        else
        {
            if(msg)
            {
                Log.debug("FTP not available!");
                ok = false;
                status = GENERIC_FAILED;
            }
        }

        if(ok)
        {
            connected = true;
            system();

            //if(getOsType().indexOf("MVS") < 0) 
            binary();

            if(initCWD.trim().equals(Settings.defaultDir) ||
                   !chdirNoRefresh(initCWD))
            {
                //System.out.println("default dir...");
                //if(!chdirNoRefresh(getPWD()))
                //{
                //System.out.println("FtpConnection should not do this...");
                //      if(!chdirNoRefresh("~"))
                //      {
                //            chdirNoRefresh("/");
                //      }
                //}
                updatePWD();
            }

            //Array of length 6 created, as that is maximum LoadSet size (need
            //public variable with that constant there for it to refer to?)
            String[] advSettings = new String[6];

            if(getOsType().indexOf("OS/2") >= 0)
            {
                LIST_DEFAULT = "LIST";
            }

            if(LIST.equals("default"))
            {
                //just get the first item (somehow it knows first is the
                //FTP list command)
                advSettings = LoadSet.loadSet(Settings.adv_settings);

                //*** IF FILE NOT FOUND, CREATE IT AND SET IT TO LIST_DEFAULT
                if(advSettings == null)
                {
                    LIST = LIST_DEFAULT;

                    SaveSet s = new SaveSet(Settings.adv_settings, LIST);
                }
                else
                {
                    LIST = advSettings[0];

                    if(LIST == null)
                    {
                        LIST = LIST_DEFAULT;
                    }
                }
            }

            if(getOsType().indexOf("MVS") >= 0)
            {
                LIST = "LIST";
            }

            //***
            fireDirectoryUpdate(this);
            fireConnectionInitialized(this);
        }
        else
        {
            fireConnectionFailed(this, new Integer(status).toString());
        }

        return status;
    }


Generated by  Doxygen 1.6.0   Back to index