Example usage for org.apache.commons.net.ftp FTPCmd RETR

List of usage examples for org.apache.commons.net.ftp FTPCmd RETR

Introduction

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

Prototype

FTPCmd RETR

To view the source code for org.apache.commons.net.ftp FTPCmd RETR.

Click Source Link

Usage

From source file:com.adaptris.ftp.ApacheFtpClientImpl.java

/**
 * Get data from a remote file//from  ww  w  .jav a  2s .  c om
 * 
 * @param destStream output target data stream
 * @param remoteFile file to be read on the server
 */
@Override
public void get(OutputStream destStream, String remoteFile) throws IOException {
    try {
        acquireLock();
        log("{} {}", FTPCmd.RETR, remoteFile);
        handleReturnValue(ftpClient().retrieveFile(remoteFile, destStream));
    } finally {
        logReply(ftpClient().getReplyStrings());
        releaseLock();
    }
}

From source file:com.adaptris.ftp.ApacheFtpClientImpl.java

/**
 * Get data as a byte array from a server file
 * //w ww  . j  a va  2 s  . com
 * @param remoteFile file to be read on the server
 */
@Override
public byte[] get(String remoteFile) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    try {
        acquireLock();
        log("{} {}", FTPCmd.RETR, remoteFile);
        try (InputStream i = ftpClient().retrieveFileStream(remoteFile); OutputStream o = out) {
            IOUtils.copy(i, o);
        }
        ftpClient().completePendingCommand();
        logReply(ftpClient().getReplyStrings());
        log("Transferred {} bytes from remote host", out.size());
    } finally {
        releaseLock();
    }
    return out.toByteArray();
}

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

@Override
public boolean retrieveFile(String remote, OutputStream local) throws IOException {
    this.pret(FTPCmd.RETR, remote);
    return super.retrieveFile(remote, local);
}

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

@Override
public InputStream retrieveFileStream(String remote) throws IOException {
    this.pret(FTPCmd.RETR, remote);
    return super.retrieveFileStream(remote);
}

From source file:com.atomicleopard.thundr.ftp.commons.FTP.java

/***
 * A convenience method to send the FTP RETR command to the server,
 * receive the reply, and return the reply code.  Remember, it is up
 * to you to manage the data connection.  If you don't need this low
 * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
 * , which will handle all low level details for you.
 * <p>/*from   www.  j a v a 2  s  .  com*/
 * @param pathname  The pathname of the file to retrieve.
 * @return The reply code received from the server.
 * @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 the
 *      command or receiving the server reply.
 ***/
public int retr(String pathname) throws IOException {
    return sendCommand(FTPCmd.RETR, pathname);
}

From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java

/**
 * Retrieves a named file from the server and writes it to the given
 * OutputStream.  This method does NOT close the given OutputStream.
 * If the current file type is ASCII, line separators in the file are
 * converted to the local representation.
 * <p>// w w  w . jav a  2s  .com
 * Note: if you have used {@link #setRestartOffset(long)},
 * the file data will start from the selected offset.
 * @param remote  The name of the remote file.
 * @param local   The local OutputStream to which to write the file.
 * @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 org.apache.commons.net.io.CopyStreamException
 *      If an I/O error occurs while actually
 *      transferring the file.  The CopyStreamException allows you to
 *      determine the number of bytes transferred and the IOException
 *      causing the error.  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 retrieveFile(String remote, OutputStream local) throws IOException {
    return _retrieveFile(FTPCmd.RETR.getCommand(), remote, local);
}

From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java

/**
 * Returns an InputStream from which a named file from the server
 * can be read.  If the current file type is ASCII, the returned
 * InputStream will convert line separators in the file to
 * the local representation.  You must close the InputStream when you
 * finish reading from it.  The InputStream itself will take care of
 * closing the parent data connection socket upon being closed.  To
 * finalize the file transfer you must call
 * {@link #completePendingCommand  completePendingCommand } and
 * check its return value to verify success.
 * <p>/*from w  w w  .  j  a va2s .c o m*/
 * Note: if you have used {@link #setRestartOffset(long)},
 * the file data will start from the selected offset.
 *
 * @param remote  The name of the remote file.
 * @return An InputStream from which the remote file can be read.  If
 *      the data connection cannot be opened (e.g., the file does not
 *      exist), null is returned (in which case you may check the reply
 *      code to determine the exact reason for failure).
 * @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 InputStream retrieveFileStream(String remote) throws IOException {
    return _retrieveFileStream(FTPCmd.RETR.getCommand(), remote);
}