⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftp.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
         * scans a particular directory         * @param dir directory to scan         * @param vpath  relative path to the base directory of the remote fileset         * always ended with a File.separator         * @param fast seems to be always true in practice         */        protected void scandir(String dir, String vpath, boolean fast) {            // avoid double scanning of directories, can only happen in fast mode            if (fast && hasBeenScanned(vpath)) {                return;            }            try {                if (!ftp.changeWorkingDirectory(dir)) {                    return;                }                String completePath = null;                if (!vpath.equals("")) {                    completePath = rootPath + remoteFileSep                        + vpath.replace(File.separatorChar, remoteFileSep.charAt(0));                } else {                    completePath = rootPath;                }                FTPFile[] newfiles = listFiles(completePath, false);                if (newfiles == null) {                    ftp.changeToParentDirectory();                    return;                }                for (int i = 0; i < newfiles.length; i++) {                    FTPFile file = newfiles[i];                    if (file != null                            && !file.getName().equals(".")                            && !file.getName().equals("..")) {                        if (isFunctioningAsDirectory(ftp, dir, file)) {                            String name = vpath + file.getName();                            boolean slowScanAllowed = true;                            if (!isFollowSymlinks() && file.isSymbolicLink()) {                                dirsExcluded.addElement(name);                                slowScanAllowed = false;                            } else if (isIncluded(name)) {                                accountForIncludedDir(name,                                    new AntFTPFile(ftp, file, completePath) , fast);                            } else {                                dirsNotIncluded.addElement(name);                                if (fast && couldHoldIncluded(name)) {                                    scandir(file.getName(),                                            name + File.separator, fast);                                }                            }                            if (!fast && slowScanAllowed) {                                scandir(file.getName(),                                        name + File.separator, fast);                            }                        } else {                            String name = vpath + file.getName();                            if (!isFollowSymlinks() && file.isSymbolicLink()) {                                filesExcluded.addElement(name);                            } else if (isFunctioningAsFile(ftp, dir, file)) {                                accountForIncludedFile(name);                            }                        }                    }                }                ftp.changeToParentDirectory();            } catch (IOException e) {                throw new BuildException("Error while communicating with FTP "                     + "server: ", e);            }        }        /**         * process included file         * @param name  path of the file relative to the directory of the fileset         */        private void accountForIncludedFile(String name) {            if (!filesIncluded.contains(name)                && !filesExcluded.contains(name)) {                if (isIncluded(name)) {                    if (!isExcluded(name)) {                        filesIncluded.addElement(name);                    } else {                        filesExcluded.addElement(name);                    }                } else {                    filesNotIncluded.addElement(name);                }            }        }        /**         *         * @param name path of the directory relative to the directory of         * the fileset         * @param file directory as file         * @param fast         */        private void accountForIncludedDir(String name, AntFTPFile file, boolean fast) {            if (!dirsIncluded.contains(name)                && !dirsExcluded.contains(name)) {                if (!isExcluded(name)) {                    if (fast) {                        if (file.isSymbolicLink()) {                            try {                                file.getClient().changeWorkingDirectory(file.curpwd);                            } catch (IOException ioe) {                                throw new BuildException("could not change directory to curpwd");                            }                            scandir(file.getLink(),                                name + File.separator, fast);                        } else {                            try {                                file.getClient().changeWorkingDirectory(file.curpwd);                            } catch (IOException ioe) {                                throw new BuildException("could not change directory to curpwd");                            }                            scandir(file.getName(),                                name + File.separator, fast);                        }                    }                    dirsIncluded.addElement(name);                } else {                    dirsExcluded.addElement(name);                    if (fast && couldHoldIncluded(name)) {                        try {                            file.getClient().changeWorkingDirectory(file.curpwd);                        } catch (IOException ioe) {                            throw new BuildException("could not change directory to curpwd");                        }                        scandir(file.getName(),                                name + File.separator, fast);                    }                }            }        }        /**         * temporary table to speed up the various scanning methods below         *         * @since Ant 1.6         */        private Map fileListMap = new HashMap();        /**         * List of all scanned directories.         *         * @since Ant 1.6         */        private Set scannedDirs = new HashSet();        /**         * Has the directory with the given path relative to the base         * directory already been scanned?         *         * <p>Registers the given directory as scanned as a side effect.</p>         *         * @since Ant 1.6         */        private boolean hasBeenScanned(String vpath) {            return !scannedDirs.add(vpath);        }        /**         * Clear internal caches.         *         * @since Ant 1.6         */        private void clearCaches() {            fileListMap.clear();            scannedDirs.clear();        }        /**         * list the files present in one directory.         * @param directory full path on the remote side         * @param changedir if true change to directory directory before listing         * @return array of FTPFile         */        public FTPFile[] listFiles(String directory, boolean changedir) {            //getProject().log("listing files in directory " + directory, Project.MSG_DEBUG);            String currentPath = directory;            if (changedir) {                try {                    boolean result = ftp.changeWorkingDirectory(directory);                    if (!result) {                        return null;                    }                    currentPath = ftp.printWorkingDirectory();                } catch (IOException ioe) {                    throw new BuildException(ioe, getLocation());                }            }            if (fileListMap.containsKey(currentPath)) {                getProject().log("filelist map used in listing files", Project.MSG_DEBUG);                return ((FTPFile[]) fileListMap.get(currentPath));            }            FTPFile[] result = null;            try {                result = ftp.listFiles();            } catch (IOException ioe) {                throw new BuildException(ioe, getLocation());            }            fileListMap.put(currentPath, result);            if (!remoteSensitivityChecked) {                checkRemoteSensitivity(result, directory);            }            return result;        }        private void forceRemoteSensitivityCheck() {            if (!remoteSensitivityChecked) {                try {                    checkRemoteSensitivity(ftp.listFiles(), ftp.printWorkingDirectory());                } catch (IOException ioe) {                    throw new BuildException(ioe, getLocation());                }            }        }        /**         * cd into one directory and         * list the files present in one directory.         * @param directory full path on the remote side         * @return array of FTPFile         */        public FTPFile[] listFiles(String directory) {            return listFiles(directory, true);        }        private void checkRemoteSensitivity(FTPFile[] array, String directory) {            if (array == null) {                return;            }            boolean candidateFound = false;            String target = null;            for (int icounter = 0; icounter < array.length; icounter++) {                if (array[icounter] != null && array[icounter].isDirectory()) {                    if (!array[icounter].getName().equals(".")                        && !array[icounter].getName().equals("..")) {                        candidateFound = true;                        target = fiddleName(array[icounter].getName());                        getProject().log("will try to cd to "                            + target + " where a directory called " + array[icounter].getName()                            + " exists", Project.MSG_DEBUG);                        for (int pcounter = 0; pcounter < array.length; pcounter++) {                            if (array[pcounter] != null                                && pcounter != icounter                                && target.equals(array[pcounter].getName())) {                                candidateFound = false;                            }                        }                        if (candidateFound) {                            break;                        }                    }                }            }            if (candidateFound) {                try {                    getProject().log("testing case sensitivity, attempting to cd to "                        + target, Project.MSG_DEBUG);                    remoteSystemCaseSensitive  = !ftp.changeWorkingDirectory(target);                } catch (IOException ioe) {                    remoteSystemCaseSensitive = true;                } finally {                    try {                        ftp.changeWorkingDirectory(directory);                    } catch (IOException ioe) {                        throw new BuildException(ioe, getLocation());                    }                }                getProject().log("remote system is case sensitive : " + remoteSystemCaseSensitive,                    Project.MSG_VERBOSE);                remoteSensitivityChecked = true;            }        }        private String fiddleName(String origin) {            StringBuffer result = new StringBuffer();            for (int icounter = 0; icounter < origin.length(); icounter++) {                if (Character.isLowerCase(origin.charAt(icounter))) {                    result.append(Character.toUpperCase(origin.charAt(icounter)));                } else if (Character.isUpperCase(origin.charAt(icounter))) {                    result.append(Character.toLowerCase(origin.charAt(icounter)));                } else {                    result.append(origin.charAt(icounter));                }            }            return result.toString();        }        /**         * an AntFTPFile is a representation of a remote file         * @since Ant 1.6         */        protected class AntFTPFile {            /**             * ftp client             */            private FTPClient client;            /**             * parent directory of the file             */            private String curpwd;            /**             * the file itself             */            private FTPFile ftpFile;            /**             *             */            private AntFTPFile parent = null;            private boolean relativePathCalculated = false;            private boolean traversesSymlinks = false;            private String relativePath = "";            /**             * constructor             * @param client ftp client variable             * @param ftpFile the file             * @param curpwd absolute remote path where the file is found             */            public AntFTPFile(FTPClient client, FTPFile ftpFile, String curpwd) {                this.client = client;                this.ftpFile = ftpFile;                this.curpwd = curpwd;            }            /**             * other constructor             * @param parent the parent file             * @param path  a relative path to the parent file             */            public AntFTPFile(AntFTPFile parent, String path) {                this.parent = parent;                this.client = parent.client;                Vector pathElements = SelectorUtils.tokenizePath(path);                try {                    boolean result = this.client.changeWorkingDirectory(parent.getAbsolutePath());                    //this should not happen, except if parent has been deleted by another process                    if (!result) {                        return;                    }                    this.curpwd = parent.getAbsolutePath();                } catch (IOException ioe) {                    throw new BuildException("could not change working dir to "                    + parent.curpwd);                }                for (int fcount = 0; fcount < pathElements.size() - 1; fcount++) {                    String currentPathElement = (String) pathElements.elementAt(fcount);                    try {                        boolean result = this.client.changeWorkingDirectory(currentPathElement);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -