Example usage for org.apache.commons.net.ftp FTPFile UNKNOWN_TYPE

List of usage examples for org.apache.commons.net.ftp FTPFile UNKNOWN_TYPE

Introduction

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

Prototype

int UNKNOWN_TYPE

To view the source code for org.apache.commons.net.ftp FTPFile UNKNOWN_TYPE.

Click Source Link

Document

A constant indicating an FTPFile is of unknown type.

Usage

From source file:lucee.runtime.net.ftp.FTPConstant.java

/**
 * @param type/*from www  .  j a  v  a2 s  .  co m*/
 * @return file type as String
 */
public static String getTypeAsString(int type) {
    if (type == FTPFile.DIRECTORY_TYPE)
        return "directory";
    else if (type == FTPFile.SYMBOLIC_LINK_TYPE)
        return "link";
    else if (type == FTPFile.UNKNOWN_TYPE)
        return "unknown";
    else if (type == FTPFile.FILE_TYPE)
        return "file";

    return "unknown";
}

From source file:ch.cyberduck.core.ftp.parser.CommonUnixFTPEntryParser.java

protected FTPFile parseFTPEntry(String typeStr, String usr, String grp, long filesize, String datestr,
        String name, String endtoken) {
    final FTPExtendedFile file = new FTPExtendedFile();
    int type;/*from ww w  . j  a v  a 2s. co m*/
    try {
        file.setTimestamp(this.parseTimestamp(datestr));
    } catch (ParseException e) {
        log.warn(e.getMessage());
    }

    // bcdlfmpSs-
    switch (typeStr.charAt(0)) {
    case 'd':
        type = FTPFile.DIRECTORY_TYPE;
        break;
    case 'l':
        type = FTPFile.SYMBOLIC_LINK_TYPE;
        break;
    case 'b':
    case 'c':
    case 'f':
    case '-':
        type = FTPFile.FILE_TYPE;
        break;
    default:
        type = FTPFile.UNKNOWN_TYPE;
    }

    file.setType(type);
    file.setUser(usr);
    file.setGroup(grp);

    int g = 4;
    for (int access = 0; access < 3; access++, g += 4) {
        // Use != '-' to avoid having to check for suid and sticky bits.
        file.setPermission(access, FTPFile.READ_PERMISSION, (!group(g).equals("-")));
        file.setPermission(access, FTPFile.WRITE_PERMISSION, (!group(g + 1).equals("-")));

        String execPerm = group(g + 2);
        if (execPerm.equals("-")) {
            file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false);
        } else {
            file.setPermission(access, FTPFile.EXECUTE_PERMISSION, Character.isLowerCase(execPerm.charAt(0)));
            if (0 == access) {
                file.setSetuid(execPerm.charAt(0) == 's' || execPerm.charAt(0) == 'S');
            }
            if (1 == access) {
                file.setSetgid(execPerm.charAt(0) == 's' || execPerm.charAt(0) == 'S');
            }
            if (2 == access) {
                file.setSticky(execPerm.charAt(0) == 't' || execPerm.charAt(0) == 'T');
            }
        }
    }

    file.setSize(filesize);

    if (null == endtoken) {
        file.setName(name);
    } else {
        // oddball cases like symbolic links, file names
        // with spaces in them.
        name += endtoken;
        if (type == FTPFile.SYMBOLIC_LINK_TYPE) {

            int end = name.indexOf(" -> ");
            // Give up if no link indicator is present
            if (end == -1) {
                file.setName(name);
            } else {
                file.setName(name.substring(0, end));
                file.setLink(name.substring(end + 4));
            }

        } else {
            file.setName(name);
        }
    }
    return file;
}

From source file:com.ai.api.util.UnixFTPEntryParser.java

/**
 * Parses a line of a unix (standard) FTP server file listing and converts
 * it into a usable format in the form of an <code> FTPFile </code>
 * instance.  If the file listing line doesn't describe a file,
 * <code> null </code> is returned, otherwise a <code> FTPFile </code>
 * instance representing the files in the directory is returned.
 * <p>//from ww w  . java2s. c  om
 * @param entry A line of text from the file listing
 * @return An FTPFile instance corresponding to the supplied entry
 */
public FTPFile parseFTPEntry(String entry) {
    FTPFile file = new FTPFile();
    file.setRawListing(entry);
    int type;
    boolean isDevice = false;

    if (matches(entry)) {
        String typeStr = group(1);
        String hardLinkCount = group(15);
        String usr = group(16);
        String grp = group(17);
        String filesize = group(18);
        String datestr = group(19) + " " + group(20);
        String name = group(21);
        String endtoken = group(22);

        try {
            //file.setTimestamp(super.parseTimestamp(datestr));
            FTPTimestampParserImplExZH Zh2En = new FTPTimestampParserImplExZH();
            file.setTimestamp(Zh2En.parseTimestamp(datestr));
        } catch (ParseException e) {
            //logger.error(e, e);
            //return null;  // this is a parsing failure too.
            //logger.info(entry+":??");
            file.setTimestamp(Calendar.getInstance());
        }

        // bcdlfmpSs-
        switch (typeStr.charAt(0)) {
        case 'd':
            type = FTPFile.DIRECTORY_TYPE;
            break;
        case 'l':
            type = FTPFile.SYMBOLIC_LINK_TYPE;
            break;
        case 'b':
        case 'c':
            isDevice = true;
            // break; - fall through
        case 'f':
        case '-':
            type = FTPFile.FILE_TYPE;
            break;
        default:
            type = FTPFile.UNKNOWN_TYPE;
        }

        file.setType(type);

        int g = 4;
        for (int access = 0; access < 3; access++, g += 4) {
            // Use != '-' to avoid having to check for suid and sticky bits
            file.setPermission(access, FTPFile.READ_PERMISSION, (!group(g).equals("-")));
            file.setPermission(access, FTPFile.WRITE_PERMISSION, (!group(g + 1).equals("-")));

            String execPerm = group(g + 2);
            if (!execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0))) {
                file.setPermission(access, FTPFile.EXECUTE_PERMISSION, true);
            } else {
                file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false);
            }
        }

        if (!isDevice) {
            try {
                file.setHardLinkCount(Integer.parseInt(hardLinkCount));
            } catch (NumberFormatException e) {
                // intentionally do nothing
            }
        }

        file.setUser(usr);
        file.setGroup(grp);

        try {
            file.setSize(Long.parseLong(filesize));
        } catch (NumberFormatException e) {
            // intentionally do nothing
        }

        if (null == endtoken) {
            file.setName(name);
        } else {
            // oddball cases like symbolic links, file names
            // with spaces in them.
            name += endtoken;
            if (type == FTPFile.SYMBOLIC_LINK_TYPE) {

                int end = name.indexOf(" -> ");
                // Give up if no link indicator is present
                if (end == -1) {
                    file.setName(name);
                } else {
                    file.setName(name.substring(0, end));
                    file.setLink(name.substring(end + 4));
                }

            } else {
                file.setName(name);
            }
        }
        return file;
    } else {
        logger.info("matches(entry) failure:" + entry);
    }
    return null;
}