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

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

Introduction

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

Prototype

FTPCmd MLST

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

Click Source Link

Usage

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

@Override
public PathAttributes find(final Path file) throws BackgroundException {
    if (file.isRoot()) {
        return PathAttributes.EMPTY;
    }//from   www . j  ava  2s . co  m
    try {
        if (session.getClient().hasFeature(FTPCmd.MLST.getCommand())) {
            if (!FTPReply
                    .isPositiveCompletion(session.getClient().sendCommand(FTPCmd.MLST, file.getAbsolute()))) {
                throw new FTPException(session.getClient().getReplyCode(),
                        session.getClient().getReplyString());
            }
            final FTPDataResponseReader reader = new FTPMlsdListResponseReader();
            final AttributedList<Path> attributes = reader.read(file.getParent(),
                    Arrays.asList(session.getClient().getReplyStrings()), new DisabledListProgressListener());
            if (attributes.contains(file)) {
                return attributes.iterator().next().attributes();
            }
        }
        throw new InteroperabilityException("No support for MLST in reply to FEAT");
    } catch (IOException e) {
        throw new FTPExceptionMappingService().map("Failure to read attributes of {0}", e, file);
    }
}

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

@Override
public PathAttributes find(final Path file) throws BackgroundException {
    if (file.isRoot()) {
        return PathAttributes.EMPTY;
    }//from  w w  w  .  ja va 2 s  . c o  m
    try {
        if (session.getClient().hasFeature(FTPCmd.MLST.getCommand())) {
            if (!FTPReply
                    .isPositiveCompletion(session.getClient().sendCommand(FTPCmd.MLST, file.getAbsolute()))) {
                throw new FTPException(session.getClient().getReplyCode(),
                        session.getClient().getReplyString());
            }
            final FTPDataResponseReader reader = new FTPMlsdListResponseReader();
            final AttributedList<Path> attributes = reader.read(file.getParent(),
                    Arrays.asList(session.getClient().getReplyStrings()), new DisabledListProgressListener());
            if (attributes.contains(file)) {
                return attributes.get(attributes.indexOf(file)).attributes();
            }
        }
        throw new InteroperabilityException("No support for MLST in reply to FEAT");
    } catch (IOException e) {
        throw new FTPExceptionMappingService().map("Failure to read attributes of {0}", e, file);
    }
}

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

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    try {/*ww  w .  ja  v a  2s  . c  o  m*/
        if (implementations.containsKey(Command.mlsd)) {
            // Note that there is no distinct FEAT output for MLSD. The presence of the MLST feature
            // indicates that both MLST and MLSD are supported.
            if (session.getClient().hasFeature(FTPCmd.MLST.getCommand())) {
                try {
                    return this.post(directory, implementations.get(Command.mlsd).list(directory, listener),
                            listener);
                } catch (InteroperabilityException | FTPInvalidListException e) {
                    this.remove(Command.mlsd);
                }
            } else {
                this.remove(Command.mlsd);
            }
        }
        if (implementations.containsKey(Command.stat)) {
            try {
                return this.post(directory, implementations.get(Command.stat).list(directory, listener),
                        listener);
            } catch (FTPInvalidListException | InteroperabilityException e) {
                this.remove(Command.stat);
            } catch (BackgroundException e) {
                if (e.getCause() instanceof FTPException) {
                    log.warn(String.format("Command STAT failed with FTP error %s", e.getMessage()));
                } else {
                    log.warn(String.format("Command STAT failed with I/O error %s", e.getMessage()));
                    new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(),
                            new DisabledPasswordStore(), listener).connect(session, PathCache.empty(),
                                    new DisabledCancelCallback());
                }
                this.remove(Command.stat);
            }
        }
        if (implementations.containsKey(Command.lista)) {
            try {
                return this.post(directory, implementations.get(Command.lista).list(directory, listener),
                        listener);
            } catch (InteroperabilityException e) {
                this.remove(Command.lista);
            } catch (FTPInvalidListException e) {
                // Empty directory listing. #7737
            }
        }
        try {
            return this.post(directory, implementations.get(Command.list).list(directory, listener), listener);
        } catch (FTPInvalidListException f) {
            // Empty directory listing
            return this.post(directory, f.getParsed(), listener);
        }
    } catch (IOException e) {
        throw new FTPExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}

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

/**
 * A convenience method to send the FTP MLST 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   w  ww  .  j a va  2  s.  c  o m
 * @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.
 * @since 3.0
 */
public int mlst() throws IOException {
    return sendCommand(FTPCmd.MLST);
}

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

/**
 * A convenience method to send the FTP MLST 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   ww w . j  a v  a  2 s.  c o m*/
 * @param path the path to report on
 * @return The reply code received from the server,
 * may be {@code null} in which case the command is sent with no parameters
 * @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.
 * @since 3.0
 */
public int mlst(String path) throws IOException {
    return sendCommand(FTPCmd.MLST, path);
}

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

/**
 * Get file details using the MLST command
 *
 * @param pathname the file or directory to list, may be {@code} null
 * @return the file details, may be {@code null}
 * @throws IOException//from ww w .  j av a2 s  . c o  m
 * @since 3.0
 */
public FTPFile mlistFile(String pathname) throws IOException {
    boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
    if (success) {
        String entry = getReplyStrings()[1].substring(1); // skip leading space for parser
        return MLSxEntryParser.parseEntry(entry);
    } else {
        return null;
    }
}