Example usage for org.apache.commons.net.ftp FTPClient sendNoOp

List of usage examples for org.apache.commons.net.ftp FTPClient sendNoOp

Introduction

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

Prototype

public boolean sendNoOp() throws IOException 

Source Link

Document

Sends a NOOP command to the FTP server.

Usage

From source file:com.jaeksoft.searchlib.scheduler.task.TaskFtpXmlFeed.java

private void checkConnect(FTPClient ftp, String server, String login, String password) throws IOException {
    try {//from  ww  w.  j ava 2 s. c o m
        if (ftp.isConnected())
            if (ftp.sendNoOp())
                return;
    } catch (FTPConnectionClosedException e) {
        Logging.warn(e);
    }
    ftp.setConnectTimeout(120000);
    ftp.setControlKeepAliveTimeout(180);
    ftp.setDataTimeout(120000);
    ftp.connect(server);
    ftp.login(login, password);
}

From source file:org.mule.transport.ftp.FtpConnectionFactory.java

public boolean validateObject(Object obj) {
    FTPClient client = (FTPClient) obj;
    try {/*from   ww  w  . ja v  a2 s. co  m*/
        return client.sendNoOp();
    } catch (IOException e) {
        return false;
    }
}

From source file:org.mule.transport.ftp.FtpMessageDispatcher.java

@Override
public RetryContext validateConnection(RetryContext retryContext) {
    FTPClient client = null;
    try {//from  ww  w  .  jav a  2 s  . c o m
        client = connector.createFtpClient(endpoint);
        client.sendNoOp();
        client.logout();
        client.disconnect();

        retryContext.setOk();
    } catch (Exception ex) {
        retryContext.setFailed(ex);
    } finally {
        try {
            if (client != null) {
                connector.releaseFtp(endpoint.getEndpointURI(), client);
            }
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to release ftp client " + client, e);
            }

        }
    }

    return retryContext;
}

From source file:org.mule.transport.ftp.FtpMessageReceiver.java

@Override
public RetryContext validateConnection(RetryContext retryContext) {
    FTPClient client = null;
    try {//from  w  ww  .  ja  v  a  2  s  .c  o m
        client = connector.createFtpClient(endpoint);
        client.sendNoOp();
        client.logout();
        client.disconnect();

        retryContext.setOk();
    } catch (Exception ex) {
        retryContext.setFailed(ex);
    } finally {
        try {
            if (client != null) {
                connector.releaseFtp(endpoint.getEndpointURI(), client);
            }
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to release ftp client " + client, e);
            }
        }
    }

    return retryContext;
}

From source file:org.springframework.integration.ftp.QueuedFtpClientPool.java

private boolean isClientAlive(FTPClient client) {
    try {/* w ww  .  j a  v  a2 s.c  om*/
        if (client.sendNoOp()) {
            return true;
        }
    } catch (IOException e) {
        log.warn("Client [" + client + "] discarded: ", e);
    }

    return false;
}

From source file:uk.sipperfly.utils.FTPUtil.java

/**
 * Upload whole directory (including its nested sub directories and files) to FTP server.
 *
 * @param ftpClient       an instance of org.apache.commons.net.ftp.FTPClient class.
 * @param remoteDirPath   Path of the destination directory on the server.
 * @param localParentDir  Path of the local directory being uploaded.
 * @param remoteParentDir Path of the parent directory of the current directory on the server (used by recursive calls).
 * @throws IOException if any network or IO error occurred.
 *///ww w  .jav a2  s.c o m
public static boolean uploadDirectory(FTPClient ftpClient, String remoteDirPath, String localParentDir,
        String remoteParentDir) throws IOException {

    System.out.println("LISTING directory: " + localParentDir);
    Logger.getLogger(GACOM).log(Level.INFO, "LISTING directory: {0}".concat(localParentDir));
    File localDir = new File(localParentDir);
    File[] subFiles = localDir.listFiles();
    if (subFiles != null && subFiles.length > 0) {
        for (File item : subFiles) {
            boolean answer = ftpClient.sendNoOp();
            if (!answer) {
                reconnect();
            }
            String status = ftpClient.getStatus();
            boolean a = ftpClient.isAvailable();
            //            if (!ftpClient.isConnected()) {
            //               reconnect();
            //            }
            String remoteFilePath = remoteDirPath + "/" + remoteParentDir + "/" + item.getName();
            if (remoteParentDir.equals("")) {
                remoteFilePath = remoteDirPath + "/" + item.getName();
            }
            if (item.isFile()) {
                // upload the file
                String localFilePath = item.getAbsolutePath();
                Logger.getLogger(GACOM).log(Level.INFO, "About to upload the file: ".concat(localFilePath));
                System.out.println("About to upload the file: " + localFilePath);
                boolean uploaded = uploadSingleFile(ftpClient, localFilePath, remoteFilePath);

                if (uploaded) {
                    Logger.getLogger(GACOM).log(Level.INFO, "UPLOADED a file to: ".concat(remoteFilePath));
                    System.out.println("UPLOADED a file to: " + remoteFilePath);
                } else {
                    System.out.println("COULD NOT upload the file: " + localFilePath);
                    Logger.getLogger(GACOM).log(Level.INFO,
                            "COULD NOT upload the file: ".concat(localFilePath));
                    Logger.getLogger(GACOM).log(Level.INFO, ftpClient.getReplyString());
                    return false;
                }
            } else {
                // create directory on the server
                boolean created = ftpClient.makeDirectory(remoteFilePath);
                if (created) {
                    System.out.println("CREATED the directory: " + remoteFilePath);
                    Logger.getLogger(GACOM).log(Level.INFO, "CREATED the directory: ".concat(remoteFilePath));
                } else {
                    System.out.println("COULD NOT create the directory: " + remoteFilePath);
                    Logger.getLogger(GACOM).log(Level.INFO,
                            "COULD NOT create the directory: ".concat(remoteFilePath));
                    Logger.getLogger(GACOM).log(Level.INFO, ftpClient.getReplyString());
                    return false;
                }

                // upload the sub directory
                String parent = remoteParentDir + "/" + item.getName();
                if (remoteParentDir.equals("")) {
                    parent = item.getName();
                }

                localParentDir = item.getAbsolutePath();
                uploadDirectory(ftpClient, remoteDirPath, localParentDir, parent);
            }
        }
    }
    return true;
}