Sie die sshexec task verwenden könnte die Befehlszeile unzip
Befehl auf dem entfernten Rechner zu nennen (vorausgesetzt, die Remote-Rechner installiert entpacken hat).
<!-- 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 '" />
Der unzip
Befehl eine Reihe anderer Optionen nehmen, sieht seine man page für weitere Informationen. Zum Beispiel ignoriert die Option -j
jede Verzeichnishierarchie innerhalb der ZIP-Dateien und legt alle extrahierten Dateien direkt im Zielverzeichnis ab. Und -o
wird zwingen, vorhandene Dateien im Zielverzeichnis ohne Aufforderung zu überschreiben.
können Sie mir bitte Beispiel geben, wo ich alle Dateien in einem bestimmten Verzeichnis entzippen und diese entpackte Datei in ein anderes Verzeichnis mit sshexec legen muss? – coolgokul
@coolgokul Ich habe ein (hoffentlich umfassendes) Beispiel hinzugefügt. –
genial groß. es funktioniert gut. zwei Fragen. 1. wie man dieses Programm entpackt, um alle Dateien in einem Ordner zu entpacken und entpackte Dateien in ein Verzeichnis zu verschieben. 2. Wenn die Dateien bereits im Zielverzeichnis entpackt sind und ich versuche, sie erneut zu entpacken, werden die Dateien ersetzt. wie man immer ja für das Ersetzen der Dateien setzt? Danke im Voraus. – coolgokul