3

antを使用してftpサーバーからサブディレクトリ内のファイルをダウンロードしようとしています。ファイルの正確なセットは既知です。それらのいくつかはサブディレクトリにあります。Antは、ルートディレクトリにあるものだけをダウンロードしているようです。リストせずにすべてのファイルをダウンロードすると機能します。

最初のftpアクションは、2番目のアクションとまったく同じことを実行する必要があります。代わりに、「隠しファイル\\ a\a.txtはシンボリックリンクではないと見なされます」というメッセージが表示されます。

ここで何が悪いのか誰か知っていますか?これはantFTPタスクのバグですか?

<?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 Netjirahttps://issues.apache.org/jira/browse/NET-324に投稿しまし

更新: antバグレポートシステムにバグレポートを追加しましたhttps://issues.apache.org/bugzilla/show_bug.cgi?id=49296

4

6 に答える 6

1

私は問題を見つけて修正したと信じています。Jira のバグレポートも参照してください: https://issues.apache.org/jira/browse/NET-324

そして、ant バグレポート システムhttps://issues.apache.org/bugzilla/show_bug.cgi?id=49296にバグレポートを追加しました。

diff --git a/libs/apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/libs/apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
--- a/libs/apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
+++ b/libs/apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
@@ -834,8 +834,7 @@
                         } else if (!result) {
                             return;
                         }
-                        this.curpwd = this.curpwd + remoteFileSep
-                            + currentPathElement;
+                        this.curpwd = getCurpwdPlusFileSep() + currentPathElement;
                     } catch (IOException ioe) {
                         throw new BuildException("could not change working dir to "
                                                  + (String) pathElements.elementAt(fcount)
@@ -895,7 +894,7 @@
              * @return absolute path as string
              */
             public String getAbsolutePath() {
-                return curpwd + remoteFileSep + ftpFile.getName();
+                return getCurpwdPlusFileSep() + ftpFile.getName();
             }
             /**
              * find out the relative path assuming that the path used to construct
@@ -1036,6 +1035,17 @@
             public String getCurpwd() {
                 return curpwd;
             }
+
+            /**
+             * @return parent directory of the AntFTPFile with a remoteFileSep appended
+             */
+            private String getCurpwdPlusFileSep() {
+                if (this.curpwd.endsWith(remoteFileSep)) {
+                    return this.curpwd;
+                }
+                return this.curpwd + remoteFileSep;
+            }
+            
             /**
              * find out if a symbolic link is encountered in the relative path of this file
              * from rootPath.
于 2010-05-15T01:25:39.823 に答える
1

これが機能する必要があるため、この回避策を作成しました。うまくいっているようですが、私は完全に満足しているわけではありません。清潔感がない。

<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>
于 2010-05-12T08:34:55.197 に答える
0

remotedir=""設定が合法かどうかはわかりません。デフォルトのルート ディレクトリを使用する場合は、完全に省略してください。

于 2010-05-11T20:20:20.800 に答える
0

最初のケースはファイル //downloads/a/a.txt を取得しようとします 2 番目のケースはファイル //a/downloads/a.txt を取得しようとします

使えないものを交換すると

<ftp action="get" verbose="true"
    server="localhost" userid="example" password="example" 
    remotedir="">
        <fileset dir="a/downloads" casesensitive="false" 
        includes="a.txt" />
</ftp>

また

<ftp action="get" verbose="true"
    server="localhost" userid="example" password="example" 
    remotedir="">
        <fileset dir="a" casesensitive="false" 
        includes="downloads/a.txt" />
</ftp>

それはうまくいくはずです。これらがニーズに合わない場合は、一致させたいファイルの完全なパスを提供していただければ、いくつかの代替案を作成できるかもしれません。

于 2010-05-12T14:57:58.483 に答える
0

Apache Commons VFS Ant Tasksを使用すると、より多くの成功を収めることができます。これらは、コピーを使用して、さまざまなファイルシステムへの読み取り/書き込みを提供します。同期およびその他の操作。これは、後で sftp、ssh、http、またはその他のシステムを使用するように変更する必要がある場合の柔軟なソリューションにもなります。ftp や ssh などのネイティブ ant タスクとは異なり、VFS 構成の大部分はファイル システムに依存せず、ファイル システムの仕様はほとんど URL の変更のみで済みます。

あなたの例は、次の行に沿ってコーディングされます。

<taskdef resource="org/apache/commons/vfs/tasks/tasks.properties"/>

<target name="example">
     <v-copy destdir="${basedir}" srcdir="ftp://example:example@localhost/downloads" includes="a/a.txt,a/b/ab.txt,c/c.txt"/>
</target>
于 2010-05-14T18:56:11.947 に答える
0

'/' を remotedir の値として設定しようとしましたか?

<ftp action="get" verbose="true"
   server="localhost" userid="example" password="example" 
   remotedir="/">
  <fileset dir="downloads" casesensitive="false" 
    includes="a/a.txt" />
</ftp>
于 2010-05-10T14:20:32.547 に答える