2012-10-16 12 views
5

Ich muss die Zip-Dateien von der lokalen Maschine kopieren und in remote-Maschine einfügen und entpacken Sie diese Dateien auf Remote-Maschine.Kopieren und Entpacken von Dateien auf Remote-Rechner - ant

Ich weiß der erste Teil kann mit dem scp (Kopieren von Zip-Dateien aus dem lokalen und Einfügen in Remote-Maschine) aber wie mache ich den zweiten Teil mit ant?

Vielen Dank im Voraus

Antwort

4

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.

+0

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

+0

@coolgokul Ich habe ein (hoffentlich umfassendes) Beispiel hinzugefügt. –

+0

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

Verwandte Themen