gpt4 book ai didi

ant ftp 不下载子目录中的文件

转载 作者:行者123 更新时间:2023-12-02 02:33:36 25 4
gpt4 key购买 nike

我正在尝试使用 ant 从 ftp 服务器下载子目录中的文件。确切的文件集是已知的。其中一些位于子目录中。Ant 似乎只下载根目录中的那些。如果我下载所有文件而不列出它们,它确实有效。

第一个 ftp 操作应该与第二个操作完全相同。相反,我得到“隐藏文件\\a\a.txt 假定不是符号链接(symbolic link)。”

有人知道这里出了什么问题吗?这是 ant FTP 任务中的错误吗?

<?xml version="1.0" encoding="utf-8"?>
<project name="example" default="example" basedir=".">
<taskdef name="ftp"
classname="org.apache.tools.ant.taskdefs.optional.net.FTP" />

<target name="example">

<!-- doesn't work -->
<ftp action="get" verbose="true"
server="localhost" userid="example" password="example"
remotedir="">
<fileset dir="downloads" casesensitive="false"
includes="a/a.txt,a/b/ab.txt,c/c.txt" />
</ftp>

<!-- works (but requires multiple ftp tasks) -->
<ftp action="get" verbose="true"
server="localhost" userid="example" password="example"
remotedir="a">
<fileset dir="downloads" casesensitive="false"
includes="a.txt,b/ab.txt" />
</ftp>
<ftp action="get" verbose="true"
server="localhost" userid="example" password="example"
remotedir="c">
<fileset dir="downloads" casesensitive="false"
includes="c.txt" />
</ftp>

</target>

</project>

更新:我向 Commons Net jira 发布了一个关于这个的错误 https://issues.apache.org/jira/browse/NET-324

更新:我在 ant 错误报告系统中添加了错误报告 https://issues.apache.org/bugzilla/show_bug.cgi?id=49296

最佳答案

因为我需要它来工作,所以我做了这个解决方法。它似乎有效,但我对此并不完全满意。感觉不干净。

<scriptdef name="my-ftp-get" language="javascript">
<attribute name="server"/>
<attribute name="userid"/>
<attribute name="password"/>
<attribute name="remotedir"/>
<attribute name="fileset_dir"/>
<attribute name="fileset_includes"/>
<![CDATA[
importClass(java.io.File);
importClass(org.apache.tools.ant.taskdefs.optional.net.FTP);
var local_basedir = "" + attributes.get("fileset_dir") + "/";
var original_includes = "" + attributes.get("fileset_includes");
var remotedir = "" + attributes.get("remotedir");
local_basedir = local_basedir.replace(/\\/g, "/");
original_includes = original_includes.replace(/\\/g, "/");
remotedir = remotedir.replace(/\\/g, "/");
var includes_arr = original_includes.split(",");
var clean_includes = {};
for (var i = 0; i < includes_arr.length; i++) {
var directory = "/";
var filename = includes_arr[i];
var split_include = includes_arr[i].split("/");
if (split_include.length > 1) {
directory = split_include[0] + "/";
filename = includes_arr[i].substring(directory.length);
}
if (!clean_includes.hasOwnProperty(directory)) {
clean_includes[directory] = [];
}
clean_includes[directory].push(filename);
}
var get_files = new FTP.Action();
get_files.setValue("get");
for (var path in clean_includes) {
var current_clean_includes = clean_includes[path].join(",");
var fileset = project.createDataType("fileset");
var ftp = self.project.createTask("ftp");
ftp.setAction(get_files);
ftp.setServer(attributes.get("server"));
ftp.setUserid(attributes.get("userid"));
ftp.setPassword(attributes.get("password"));
ftp.setRemotedir(remotedir + path);
fileset.setDir(new File(local_basedir + path));
fileset.setIncludes(current_clean_includes);
ftp.addFileset(fileset);
ftp.perform();
}
]]>
</scriptdef>

<my-ftp-get
server="localhost" userid="example" password="example"
remotedir=""
fileset_dir="downloads" casesensitive="false"
fileset_includes="a/a.txt,a/b/ab.txt">
</my-ftp-get>

关于ant ftp 不下载子目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2790570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com