Ant:将目录从一个 Windows 系统复制到另一个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7357634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:02:13  来源:igfitidea点击:

Ant: copying a directory from one windows system to another

javawindowsant

提问by Abhinav Garg

How to copy a directory from a windows system to a remote windows system using ant

如何使用ant将目录从Windows系统复制到远程Windows系统

there is one scp command and FTP command, please provide me an example to perform this task using scp and ftp.

有一个 scp 命令和 FTP 命令,请提供一个使用 scp 和 ftp 执行此任务的示例。

Also scp requires SSH which is not common for windows system.

scp 还需要 SSH,这在 Windows 系统中并不常见。

So how to use SCP on windows system using ant

那么如何使用ant在windows系统上使用SCP

Also if you know any better approach for windows system using ant or java, please share

另外,如果您知道使用 ant 或 java 的 windows 系统的任何更好的方法,请分享

Also there is one SC command(don't know how to use it)

还有一个SC命令(不知道怎么用)

采纳答案by coolcfan

Download:

下载:

<scp file="${username}:${password}@${ip}:${path-to-file}" todir="${dir}" trust="true" />

or Upload:

或上传:

<scp file="${path-to-file}" todir="${username}:${password}@${ip}:${dir}" trust="true" />  

Ant scp task provides attributes such as localFile and remoteFile to replace "file", and localTofile / localTodir and remoteTofile / remoteTodir to replace "dir". Using these attributes can help avoid confusion when you need some scp tasks to get files from the server to local machine, while others to upload files from the local machine to server.
Like this (for uploading):

Ant scp 任务提供localFile 和remoteFile 等属性替换“file”,localTofile/localTodir 和remoteTofile/remoteTodir 替换“dir”。当您需要一些 scp 任务将文件从服务器获取到本地计算机,而其他任务将文件从本地计算机上传到服务器时,使用这些属性可以帮助避免混淆。
像这样(用于上传):

<scp localFile="${path-to-file}" remoteTodir="${username}:${password}@${ip}:${dir}" trust="true" />

Check the ant manual to see more information: http://ant.apache.org/manual/Tasks/scp.html

查看 ant 手册以查看更多信息:http: //ant.apache.org/manual/Tasks/scp.html

Note:
1. Avoid copying multiple files; Copy a zip archive and a ant build file together with it, and unzip on target machine.
2. Using scp, you need to setup ssh server on the target machine; you also need to put jsch.jar in your ANT_HOME/lib. The jsch.jar can be downloaded from

注意:
1. 避免复制多个文件;复制一个 zip 存档和一个 ant 构建文件,并在目标机器上解压。
2、使用scp,需要在目标机器上设置ssh服务器;您还需要将 jsch.jar 放在您的 ANT_HOME/lib 中。jsch.jar 可以从

http://www.jcraft.com/jsch/index.html

http://www.jcraft.com/jsch/index.html

回答by Vijay Shanker Dubey

You should go for using FTP to copy files between the windows machines. There are other protocal too, but you should go with FTP.

您应该使用FTP在Windows机器之间复制文件。还有其他协议,但你应该使用 FTP。

A sample for using FTP.

使用 FTP 的示例。

<ftp server="${server.location}"
   remotedir="${directory.to.copy}"
   userid="${ftp.username}"
   password="${ftp.password}"
   depends="yes">
   <fileset dir="**Files****"/>
</ftp>

You can further look for details here. There are many options to try there.

您可以在此处进一步查找详细信息。有很多选择可以尝试。

回答by Hayk

First you download jsch-0.1.53.jar file from http://www.jcraft.com/jsch/ in your C:\apache-ant-1.8.2\lib folder. Then have below line of code in your build.xml

首先,您从C:\apache-ant-1.8.2\lib 文件夹中的http://www.jcraft.com/jsch/下载 jsch-0.1.53.jar 文件。然后在你的 build.xml 中有下面的代码行

<scp file="${userName}:${password}@${${ip_address}:${directory}/${FileName}" todir="${localDir_Where_to _Copy}" trust="true" />

Then have above line of code in your build.xml

然后在你的 build.xml 中有上面的代码行

回答by Hyman Mason

To copy a directory from your local host to a remote host using the ant scp, you have to specify the parent of the directory to the fileset and include the directory name eg.

要使用 ant scp 将目录从本地主机复制到远程主机,您必须为文件集指定目录的父目录并包含目录名称,例如。

<scp todir="user@hostname:/destination/dir/" keyfile="id_dsa" passphrase="abc" sftp="true" >
    <fileset dir="${parentDir}/"  >
        <include name="**/${dirToCopy}/" />
    </fileset>
</scp> 

sftp="true" helped another user on this subject so I included it. In my case I believe that adding the "/" at the end of the parentDir and dirToCopy, which signifies a directory at the command line, finally let me copy a directory and not just it's contents.

sftp="true" 在这个主题上帮助了另一个用户,所以我把它包括在内。就我而言,我相信在 parentDir 和 dirToCopy 的末尾添加“/”,这表示命令行中的目录,最终让我复制一个目录而不仅仅是它的内容。