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

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

Introduction

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

Prototype

public static boolean isPositiveIntermediate(int reply) 

Source Link

Document

Determine if a reply code is a positive intermediate response.

Usage

From source file:org.apache.ftpserver.clienttests.RenameTest.java

public void testRenameWithNullRntoPath() throws Exception {
    TEST_FILE1.createNewFile();//from  w  ww. java 2s.  c  om

    assertTrue(TEST_FILE1.exists());
    assertFalse(TEST_FILE2.exists());

    assertTrue(FTPReply.isPositiveIntermediate(client.rnfr(TEST_FILE1.getName())));
    assertTrue(FTPReply.isNegativePermanent(client.rnto(null)));

    assertTrue(TEST_FILE1.exists());
    assertFalse(TEST_FILE2.exists());
}

From source file:org.apache.nutch.protocol.ftp.Client.java

/***
 * Login to the FTP server using the provided username and password.
 * <p>/*from   w ww  . j  a  v a2  s . co  m*/
 * 
 * @param username
 *          The username to login under.
 * @param password
 *          The password to use.
 * @return True if successfully completed, false if not.
 * @exception FTPConnectionClosedException
 *              If the FTP server prematurely closes the connection as a
 *              result of the client being idle or some other reason causing
 *              the server to send FTP reply code 421. This exception may be
 *              caught either as an IOException or independently as itself.
 * @exception IOException
 *              If an I/O error occurs while either sending a command to the
 *              server or receiving a reply from the server.
 ***/
public boolean login(String username, String password) throws IOException {
    user(username);

    if (FTPReply.isPositiveCompletion(getReplyCode()))
        return true;

    // If we get here, we either have an error code, or an intermmediate
    // reply requesting password.
    if (!FTPReply.isPositiveIntermediate(getReplyCode()))
        return false;

    return FTPReply.isPositiveCompletion(pass(password));
}

From source file:org.mousephenotype.dcc.utils.net.ftp.FTPUtils.java

public boolean download(String filename, String destFilename) throws IOException {
    boolean success = false;
    InputStream retrieveFileStream = this.ftpClient.retrieveFileStream(filename);
    ///*from   w  w w.ja v  a2 s  . c  om*/
    if (!FTPReply.isPositiveIntermediate(this.ftpClient.getReplyCode())) {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(retrieveFileStream);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
                new FileOutputStream(destFilename, false));
        try {
            int c;
            while ((c = bufferedInputStream.read()) != -1) {
                bufferedOutputStream.write(c);
            }
        } finally {
            success = this.ftpClient.completePendingCommand();
            if (bufferedInputStream != null) {
                bufferedInputStream.close();
            }
            if (bufferedOutputStream != null) {
                bufferedOutputStream.close();
            }
        }
    } else {
        retrieveFileStream.close();
    }
    return success;
}