将文件复制并解压到远程计算机-ant
我需要复制本地机器上的zip文件,粘贴到远程机器上,然后在远程机器上解压这些文件 我知道第一部分可以使用scp(从本地复制zip文件并粘贴到远程机器)完成,但是如何使用ant完成第二部分呢 提前感谢您可以使用调用远程计算机上的命令行将文件复制并解压到远程计算机-ant,ant,ssh,exec,scp,Ant,Ssh,Exec,Scp,我需要复制本地机器上的zip文件,粘贴到远程机器上,然后在远程机器上解压这些文件 我知道第一部分可以使用scp(从本地复制zip文件并粘贴到远程机器)完成,但是如何使用ant完成第二部分呢 提前感谢您可以使用调用远程计算机上的命令行解压命令(假设远程计算机已安装解压) unzip命令可以使用许多其他选项,有关详细信息,请参阅其。例如,-j选项将忽略zip文件中的任何目录层次结构,并将所有提取的文件直接放在目标目录中。并且-o将强制覆盖目标目录中的现有文件,而无需提示。您能给我一个例子,我需要
解压
命令(假设远程计算机已安装解压)
unzip
命令可以使用许多其他选项,有关详细信息,请参阅其。例如,-j
选项将忽略zip文件中的任何目录层次结构,并将所有提取的文件直接放在目标目录中。并且-o
将强制覆盖目标目录中的现有文件,而无需提示。您能给我一个例子,我需要在一个特定目录中解压所有文件,并使用sshexec将这些解压文件放在其他目录中吗?太棒了。工作正常。两个问题。1.如何使这个程序解压一个文件夹中的所有文件,并将提取的文件移动到一个目录中。?2.如果文件已经在目标目录中解压,并且如果我再次尝试解压,它会要求替换文件吗?如何始终设置“是”以替换文件?提前谢谢。@coolgokul我不完全确定你所说的1是什么意思,但我已经添加了一些可能有用的细节。太棒了。。工作很好。。我的第一个问题是,假设我有一个名为“sources”的文件夹,其中有许多zip文件。(file1.zip、abc.zip、123.zip和命名为文件夹的特殊字符等)。。。现在我需要解压sources文件夹中的所有文件,并将所有解压后的文件放入“Temp”文件夹。你知道怎么做吗?我想上面的代码就是这么做的-你的“源”目录是archives
属性(本地包含原始zip文件的目录),你的“Temp”文件夹是unzip.destination
(服务器上的文件夹,从这些文件解压的内容将在其中结束)。如果您希望所有解压的文件直接在“Temp”中结束,而不是在子目录中结束,则只需添加-j
,即解压-j-d${unzip.destination}..
<!-- 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 '" />