You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

scp.html 8.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>SCP Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="scp">SCP</a></h2>
  8. <h3>Description</h3>
  9. <p><em>since Ant 1.6</em></p>
  10. <p>Copies a file or FileSet to or from a remote machine running SSH daemon.
  11. FileSet <i>only</i> works for copying files from the local machine to a
  12. remote machine.</p>
  13. <p><b>Note:</b> This task depends on external libraries not included
  14. in the Ant distribution. See <a
  15. href="../install.html#librarydependencies">Library Dependencies</a>
  16. for more information. This task has been tested with jsch-0.1.2 to
  17. jsch-0.1.14.</p>
  18. <h3>Parameters</h3>
  19. <table border="1" cellpadding="2" cellspacing="0">
  20. <tr>
  21. <td valign="top"><b>Attribute</b></td>
  22. <td valign="top"><b>Description</b></td>
  23. <td align="center" valign="top"><b>Required</b></td>
  24. </tr>
  25. <tr>
  26. <td valign="top">file</td>
  27. <td valign="top">The file to copy. This can be a local path or a
  28. remote path of the form <i>user[:password]@host:/directory/path</i>.
  29. <i>:password</i> can be ommitted if you use key based
  30. authentication or specify the password attribute. The way remote
  31. path is recognized is whether it contains @ character or not. This
  32. will not work if your localPath contains @ character.</td>
  33. <td valign="top" align="center">Yes, unless a nested
  34. <code>&lt;fileset&gt;</code> element is used.</td>
  35. </tr>
  36. <tr>
  37. <td valign="top">localFile</td>
  38. <td valign="top">This is an alternative to the file attribute. But
  39. this must always point to a local file. The reason this was added
  40. was that when you give file attribute it is treated as remote if
  41. it contains @ character. This character can exist also in local
  42. paths. <em>since Ant 1.6.2</em></td>
  43. <td valign="top" align="center">Alternative to file attribute.</td>
  44. </tr>
  45. <tr>
  46. <td valign="top">remoteFile</td>
  47. <td valign="top">This is an alternative to the file attribute. But
  48. this must always point to a remote file. <em>since Ant 1.6.2</em></td>
  49. <td valign="top" align="center">Alternative to file attribute.</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">todir</td>
  53. <td valign="top">The directory to copy to. This can be a local path
  54. or a remote path of the form <i>user[:password]@host:/directory/path</i>.
  55. <i>:password</i> can be ommitted if you use key based
  56. authentication or specify the password attribute. The way remote
  57. path is recognized is whether it contains @ character or not. This
  58. will not work if your localPath contains @ character.</td>
  59. <td valian="top" align="center">Yes</td>
  60. </tr>
  61. <tr>
  62. <td valign="top">localTodir</td>
  63. <td valign="top">This is an alternative to the todir
  64. attribute. But this must always point to a local directory. The
  65. reason this was added was that when you give todir attribute it is
  66. treated as remote if it contains @ character. This character can
  67. exist also in local paths. <em>since Ant 1.6.2</em></td>
  68. <td valian="top" align="center">Alternative to todir attribute.</td>
  69. </tr>
  70. <tr>
  71. <td valign="top">remoteTodir</td>
  72. <td valign="top">This is an alternative to the todir
  73. attribute. But this must always point to a remote directory.
  74. <em>since Ant 1.6.2</em></td>
  75. <td valian="top" align="center">Alternative to todir attribute.</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">port</td>
  79. <td valign="top">The port to connect to on the remote host.</td>
  80. <td valian="top" align="center">No, defaults to 22.</td>
  81. </tr>
  82. <tr>
  83. <td valign="top">trust</td>
  84. <td valign="top">This trusts all unknown hosts if set to yes/true.<br>
  85. <strong>Note</strong> If you set this to false (the default), the
  86. host you connect to must be listed in your knownhosts file, this
  87. also implies that the file exists.</td>
  88. <td valian="top" align="center">No, defaults to No.</td>
  89. </tr>
  90. <tr>
  91. <td valign="top">knownhosts</td>
  92. <td valign="top">This sets the known hosts file to use to validate
  93. the identity of the remote host. This must be a SSH2 format file.
  94. SSH1 format is not supported.</td>
  95. <td valian="top" align="center">No, defaults to
  96. ${user.home}/.ssh/known_hosts.</td>
  97. </tr>
  98. <tr>
  99. <td valign="top">failonerror</td>
  100. <td valign="top">Whether to halt the build if the transfer fails.
  101. </td>
  102. <td valign="top" align="center">No; defaults to true.</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">password</td>
  106. <td valign="top">The password.</td>
  107. <td valign="top" align="center">Not if you are using key based
  108. authentication or the password has been given in the file or
  109. todir attribute.</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">keyfile</td>
  113. <td valign="top">Location of the file holding the private key.</td>
  114. <td valign="top" align="center">Yes, if you are using key based
  115. authentication.</td>
  116. </tr>
  117. <tr>
  118. <td valign="top">passphrase</td>
  119. <td valign="top">Passphrase for your private key.</td>
  120. <td valign="top" align="center">Yes, if you are using key based
  121. authentication.</td>
  122. </tr>
  123. <tr>
  124. <td valign="top">verbose</td>
  125. <td valign="top">Determines whether SCP outputs verbosely to the
  126. user. Currently this means outputting dots/stars showing the
  127. progress of a file transfer. <em>since Ant 1.6.2</em></td>
  128. <td valign="top" align="center">No; defaults to false.</td>
  129. </tr>
  130. </table>
  131. <h3>Parameters specified as nested elements</h3>
  132. <h4>fileset</h4>
  133. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
  134. sets of files to copy.
  135. To use a fileset, the <code>todir</code> attribute must be set.</p>
  136. <h3>Examples</h3>
  137. <p><b>Copy a single local file to a remote machine</b></p>
  138. <pre>
  139. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user:password@somehost:/home/chuck&quot;/&gt;
  140. </pre>
  141. <p><b>Copy a single local file to a remote machine with separate
  142. password attribute</b></p>
  143. <pre>
  144. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user@somehost:/home/chuck&quot; password=&quot;password&quot;/&gt;
  145. </pre>
  146. <p><b>Copy a single local file to a remote machine using key base
  147. authentication.</b></p>
  148. <pre>
  149. &lt;scp file=&quot;myfile.txt&quot;
  150. todir=&quot;user@somehost:/home/chuck&quot;
  151. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  152. passphrase=&quot;my extremely secret passphrase&quot;
  153. /&gt;
  154. </pre>
  155. <p><b>Copy a single remote file to a local directory</b></p>
  156. <pre>
  157. &lt;scp file=&quot;user:password@somehost:/home/chuck/myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
  158. </pre>
  159. <p><b>Copy a remote directory to a local directory</b></p>
  160. <pre>
  161. &lt;scp file=&quot;user:password@somehost:/home/chuck/*&quot; todir=&quot;/home/sara&quot; /&gt;
  162. </pre>
  163. <p><b>Copy a local directory to a remote directory</b></p>
  164. <pre>
  165. &lt;scp todir=&quot;user:password@somehost:/home/chuck/&quot;&gt;
  166. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  167. &lt;/scp&gt;
  168. </pre>
  169. <p><b>Copy a set of files to a directory</b></p>
  170. <pre>
  171. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  172. &lt;fileset dir=&quot;src_dir&quot;&gt;
  173. &lt;include name=&quot;**/*.java&quot;/&gt;
  174. &lt;/fileset&gt;
  175. &lt;/scp&gt;
  176. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  177. &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
  178. &lt;/scp&gt;
  179. </pre>
  180. <p><strong>Security Note:</strong> Hard coding passwords and/or usernames
  181. in scp task can be a serious security hole. Consider using variable
  182. substituion and include the password on the command line. For example:<br>
  183. <pre>
  184. &lt;scp todir=&quot;${username}:${password}@host:/dir&quot; ...&gt;
  185. </pre>
  186. Invoke ant with the following command line:
  187. <pre>
  188. ant -Dusername=me -Dpassword=mypassword target1 target2
  189. </pre>
  190. </p>
  191. <p><strong>Unix Note:</strong> File permissions are not retained when files
  192. are copied; they end up with the default <code>UMASK</code> permissions
  193. instead. This is caused by the lack of any means to query or set file
  194. permissions in the current Java runtimes. If you need a permission-
  195. preserving copy function, use <code>&lt;exec executable="scp" ... &gt;</code>
  196. instead.
  197. </p>
  198. <hr><p align="center">Copyright &copy; 2003-2004 The Apache Software Foundation.
  199. All rights Reserved.</p>
  200. </body>
  201. </html>