Example usage for org.apache.commons.net.ftp FTPReply NOT_LOGGED_IN

List of usage examples for org.apache.commons.net.ftp FTPReply NOT_LOGGED_IN

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPReply NOT_LOGGED_IN.

Prototype

int NOT_LOGGED_IN

To view the source code for org.apache.commons.net.ftp FTPReply NOT_LOGGED_IN.

Click Source Link

Usage

From source file:ch.cyberduck.core.ftp.FTPExceptionMappingService.java

private BackgroundException handle(final FTPException e, final StringBuilder buffer) {
    final int status = e.getCode();
    switch (status) {
    case FTPReply.INSUFFICIENT_STORAGE:
    case FTPReply.STORAGE_ALLOCATION_EXCEEDED:
        return new QuotaException(buffer.toString(), e);
    case FTPReply.NOT_LOGGED_IN:
        return new LoginFailureException(buffer.toString(), e);
    case FTPReply.FAILED_SECURITY_CHECK:
    case FTPReply.DENIED_FOR_POLICY_REASONS:
    case FTPReply.NEED_ACCOUNT:
    case FTPReply.NEED_ACCOUNT_FOR_STORING_FILES:
    case FTPReply.FILE_NAME_NOT_ALLOWED:
    case FTPReply.ACTION_ABORTED:
        return new AccessDeniedException(buffer.toString(), e);
    case FTPReply.UNAVAILABLE_RESOURCE:
    case FTPReply.FILE_UNAVAILABLE:
        // Requested action not taken. File unavailable (e.g., file not found, no access)
        return new NotfoundException(buffer.toString(), e);
    case FTPReply.SERVICE_NOT_AVAILABLE:
        return new ConnectionRefusedException(buffer.toString(), e);
    }/*  ww w. j  a  v a 2s  . co m*/
    return new InteroperabilityException(buffer.toString(), e);
}

From source file:de.thischwa.pmcms.tool.connection.ftp.FtpConnectionManager.java

private void checkReply() {
    int replyCode = ftpClient.getReplyCode();

    // close connection, if dropped, so that isConnected() return false
    if (replyCode == FTPReply.SERVICE_NOT_AVAILABLE)
        close();//from www.j a v a  2  s . c om

    logger.debug("[FTP] " + ftpClient.getReplyString());

    // throw exceptions depending on the replyCode, if is not positiv
    if (!FTPReply.isPositiveCompletion(replyCode)) {
        if (replyCode == FTPReply.CODE_503 || replyCode == FTPReply.NEED_PASSWORD
                || replyCode == FTPReply.NOT_LOGGED_IN)
            throw new ConnectionAuthentificationException(ftpClient.getReplyString());
        else
            throw new ConnectionRunningException(ftpClient.getReplyString());
    }
}

From source file:net.sf.webphotos.sync.FTP.SyncObject.java

/**
 * Conecta ao servidor FTP. Retorna uma confirmao da conexo atravs de um
 * boolean. TODO: remontar a funo para que use somente dados externos a
 * classe/* w  w  w.j a  va2 s .  c om*/
 *
 * @return Valor lgico que confirma a conexo.
 */
@Override
public boolean connect() {
    boolean conectado = false;

    ftpHost = Util.getProperty("servidorFTP");
    ftpPort = Util.getConfig().getInt("FTPport");

    String ftpProxyHost = Util.getProperty("FTPproxyHost");
    int ftpProxyPort;
    try {
        ftpProxyPort = Util.getConfig().getInt("FTPproxyPort");
    } catch (Exception e) {
        ftpProxyPort = 0;
    }

    Util.log("Iniciando conexo com " + ftpHost);
    try {
        //TODO: Preparar o suporte a mltiplas lnguas
        FTPClientConfig auxConfig = new FTPClientConfig(FTPClientConfig.SYST_NT);
        configure(auxConfig);
        Util.out.println("Timeout (antes): " + getDefaultTimeout());
        setDefaultTimeout(25000);
        Util.out.println("Timeout (depois): " + getDefaultTimeout());

        //TODO: Testar o acesso via Proxy
        //      usando System.getProperties().put()
        //      http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html
        if (ftpProxyHost == null && ftpProxyPort != 0) {
            System.getProperties().put("ftp.proxyHost", ftpProxyHost);
            System.getProperties().put("ftp.proxyPort", ftpProxyPort);
        }

        super.connect(ftpHost, ftpPort);
        reply = getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            disconnect("[FtpClient.connect]/ERRO: no foi possivel conectar");
            return false;
        }
        Util.log("ok " + ftpHost + " encontrado.. autenticando..");

        SyncEvent ev = null;
        if (syncListener != null) {
            ev = new SyncEvent(this);
        }
        reply = FTPReply.NOT_LOGGED_IN;
        do {

            if (syncListener != null && ev != null) {
                syncListener.logonStarted(ev);
            }
            Util.log("servidor: " + ftpHost + " em " + ftpRoot + "\nsolicitando conexo...");

            login(usuario, new String(senha));
            Util.log("usurio: " + usuario + " senha: ***");
            reply = getReplyCode();
            retry--;

        } while (reply != FTPReply.USER_LOGGED_IN && retry >= 0);

        if (reply != FTPReply.USER_LOGGED_IN) {
            disconnect("[FtpClient.connect]/ERRO: login/senha incorreto.");
            return conectado;
        } else {
            // conexo bem sucedida... armazenamos o nome/login
            BancoImagem.getBancoImagem().setUserFTP(getUsuario());
            BancoImagem.getBancoImagem().setPasswordFTP(getSenha());
        }

        Util.log("ok conexo aceita..");
        // autenticao ok..

        setFileType(FTPClient.BINARY_FILE_TYPE);
        //ftp.enterRemotePassiveMode();
        // TODO: Achar uma alternativa para realizar o logging do FTP
        //ftp.setLogFile("ftp.log");

        // tenta ir ao diretrio FTPRoot... caso no consiga, tenta criar
        changeWorkingDirectory(ftpRoot);
        if (getReplyCode() != FTPReply.CODE_250) {
            Util.log(ftpRoot + " no existe..criando");
            if (makeDirectory(ftpRoot)) {
                Util.log("[FtpClient.connect]/ERRO: no foi possvel criar diretrio " + ftpRoot + " Retorno: "
                        + reply);
                disconnect("no foi possvel criar diretrio");
                return conectado;
            }
            changeWorkingDirectory(ftpRoot);
            reply = getReplyCode();
            if (reply != FTPReply.CODE_250) {
                disconnect("[FtpClient.connect]/ERRO: no foi possvel entrar no diretrio " + ftpRoot
                        + " que foi recm criado.");
                return conectado;
            }
        }
        conectado = true;
        getSyncListener().connected(new SyncEvent(this));
    } catch (Exception e) {
        conectado = false;
        log.error(e);
        disconnect("[FtpClient.connect]/ERRO: no foi possivel manter esta conexo");
    }

    return conectado;

}

From source file:ch.cyberduck.core.ftp.FTPClient.java

private boolean initFeatureMap() throws IOException {
    if (features == null) {
        // Don't create map here, because next line may throw exception
        final int reply = feat();
        if (FTPReply.NOT_LOGGED_IN == reply) {
            return false;
        } else {/*from   w w w . j a v  a  2  s. c o m*/
            // we init the map here, so we don't keep trying if we know the command will fail
            features = new HashMap<String, Set<String>>();
        }
        boolean success = FTPReply.isPositiveCompletion(reply);
        if (!success) {
            return false;
        }
        for (String l : getReplyStrings()) {
            if (l.startsWith(" ")) { // it's a FEAT entry
                String key;
                String value = "";
                int varsep = l.indexOf(' ', 1);
                if (varsep > 0) {
                    key = l.substring(1, varsep);
                    value = l.substring(varsep + 1);
                } else {
                    key = l.substring(1);
                }
                key = key.toUpperCase(Locale.ROOT);
                Set<String> entries = features.get(key);
                if (entries == null) {
                    entries = new HashSet<String>();
                    features.put(key, entries);
                }
                entries.add(value);
            }
        }
    }
    return true;
}