5

zip ファイルをローカル マシンからコピーしてリモート マシンに貼り付け、それらのファイルをリモート マシンで解凍する必要があります。

最初の部分はscpを使用して実行できることは知っていますが(ローカルからzipファイルをコピーしてリモートマシンに貼り付けます)、antを使用して2番目の部分を実行するにはどうすればよいですか?

前もって感謝します

4

1 に答える 1

4

sshexec タスクを使用して、リモート マシンでコマンド ラインunzipコマンドを呼び出すことができます (リモート マシンに unzip がインストールされていると仮定します)。

<!-- local directory containing the files to copy -->
<property name="archives" location="C:\path\to\zipfiles" />
<property name="archives.destination" value="/home/testuser/archives" />
<property name="unzip.destination" value="/home/testuser/unpacked" />

<fileset id="zipfiles.to.copy" dir="${archives}" includes="*.zip" />

<!-- copy the archives to the remote server -->
<scp todir="${user}:${password}@host.example.com:${archives.destination}">
  <fileset refid="zipfiles.to.copy" />
</scp>

<!-- Build the command line for unzip - the idea here is to turn the local
     paths into the corresponding paths on the remote, i.e. to turn
     C:\path\to\zipfiles\file1.zip;C:\path\to\zipfiles\file2.zip... into
     /home/testuser/archives/file1.zip /home/testuser/archives/file2.zip

     For this to work there must be no spaces in any of the zipfile names.
-->
<pathconvert dirsep="/" pathsep=" " property="unzip.files" refid="zipfiles.to.copy">
  <map from="${archives}" to="${archives.destination}" />
</pathconvert>

<!-- execute the command.  Use the "-d" option to unzip so it will work
     whatever the "current" directory on the remote side -->
<sshexec host="host.example.com" username="${user}" password="${password}"
  command="/bin/sh -c '
    for zipfile in ${unzip.files}; do
      /usr/bin/unzip -d ${unzip.destination} $$zipfile ; done '" />

このunzipコマンドは、他にも多くのオプションを使用できます。詳細については、 man ページを参照してください。たとえば、この-jオプションは、zip ファイル内のディレクトリ階層を無視し、抽出されたすべてのファイルをターゲット ディレクトリに直接配置します。また-o、プロンプトを表示せずに、ターゲット ディレクトリ内の既存のファイルを強制的に上書きします。

于 2012-10-16T19:40:22.637 に答える