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 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>SCP Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="scp">SCP</a></h2>
  23. <h3>Description</h3>
  24. <p><em>since Ant 1.6</em></p>
  25. <p>Copies a file or FileSet to or from a (remote) machine running an SSH daemon.
  26. FileSet <i>only</i> works for copying files from the local machine to a
  27. remote machine.</p>
  28. <p><b>Note:</b> This task depends on external libraries not included
  29. in the Ant distribution. See <a
  30. href="../install.html#librarydependencies">Library Dependencies</a>
  31. for more information. This task has been tested with jsch-0.1.2 and later.</p>
  32. <p>See also the <a href="sshexec.html">sshexec task</a></p>
  33. <h3>Parameters</h3>
  34. <table border="1" cellpadding="2" cellspacing="0">
  35. <tr>
  36. <td valign="top"><b>Attribute</b></td>
  37. <td valign="top"><b>Description</b></td>
  38. <td align="center" valign="top"><b>Required</b></td>
  39. </tr>
  40. <tr>
  41. <td valign="top">file</td>
  42. <td valign="top">The file to copy. This can be a local path or a
  43. remote path of the form <i>user[:password]@host:/directory/path</i>.
  44. <i>:password</i> can be omitted if you use key based
  45. authentication or specify the password attribute. The way remote
  46. path is recognized is whether it contains @ character or not. This
  47. will not work if your localPath contains @ character.</td>
  48. <td valign="top" align="center">Yes, unless a nested
  49. <code>&lt;fileset&gt;</code> element is used.</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">localFile</td>
  53. <td valign="top">This is an alternative to the file attribute. But
  54. this must always point to a local file. The reason this was added
  55. was that when you give file attribute it is treated as remote if
  56. it contains @ character. This character can exist also in local
  57. paths. <em>since Ant 1.6.2</em></td>
  58. <td valign="top" align="center">Alternative to file attribute.</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">remoteFile</td>
  62. <td valign="top">This is an alternative to the file attribute. But
  63. this must always point to a remote file. <em>since Ant 1.6.2</em></td>
  64. <td valign="top" align="center">Alternative to file attribute.</td>
  65. </tr>
  66. <tr>
  67. <td valign="top">todir</td>
  68. <td valign="top">The directory to copy to. This can be a local path
  69. or a remote path of the form <i>user[:password]@host:/directory/path</i>.
  70. <i>:password</i> can be omitted if you use key based
  71. authentication or specify the password attribute. The way remote
  72. path is recognized is whether it contains @ character or not. This
  73. will not work if your localPath contains @ character.</td>
  74. <td valian="top" align="center">Yes</td>
  75. </tr>
  76. <tr>
  77. <td valign="top">localTodir</td>
  78. <td valign="top">This is an alternative to the todir
  79. attribute. But this must always point to a local directory. The
  80. reason this was added was that when you give todir attribute it is
  81. treated as remote if it contains @ character. This character can
  82. exist also in local paths. <em>since Ant 1.6.2</em></td>
  83. <td valian="top" align="center">Alternative to todir attribute.</td>
  84. </tr>
  85. <tr>
  86. <td valign="top">localTofile</td>
  87. <td valign="top">Changes the file name to the given name while
  88. receiving it, only useful if receiving a single file. <em>since
  89. Ant 1.6.2</em></td>
  90. <td valian="top" align="center">Alternative to todir attribute.</td>
  91. </tr>
  92. <tr>
  93. <td valign="top">remoteTodir</td>
  94. <td valign="top">This is an alternative to the todir
  95. attribute. But this must always point to a remote directory.
  96. <em>since Ant 1.6.2</em></td>
  97. <td valian="top" align="center">Alternative to todir attribute.</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">remoteTofile</td>
  101. <td valign="top">Changes the file name to the given name while
  102. sending it, only useful if sending a single file. <em>since
  103. Ant 1.6.2</em></td>
  104. <td valian="top" align="center">Alternative to todir attribute.</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">port</td>
  108. <td valign="top">The port to connect to on the remote host.</td>
  109. <td valian="top" align="center">No, defaults to 22.</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">trust</td>
  113. <td valign="top">This trusts all unknown hosts if set to yes/true.<br>
  114. <strong>Note</strong> If you set this to false (the default), the
  115. host you connect to must be listed in your knownhosts file, this
  116. also implies that the file exists.</td>
  117. <td valian="top" align="center">No, defaults to No.</td>
  118. </tr>
  119. <tr>
  120. <td valign="top">knownhosts</td>
  121. <td valign="top">This sets the known hosts file to use to validate
  122. the identity of the remote host. This must be a SSH2 format file.
  123. SSH1 format is not supported.</td>
  124. <td valian="top" align="center">No, defaults to
  125. ${user.home}/.ssh/known_hosts.</td>
  126. </tr>
  127. <tr>
  128. <td valign="top">failonerror</td>
  129. <td valign="top">Whether to halt the build if the transfer fails.
  130. </td>
  131. <td valign="top" align="center">No; defaults to true.</td>
  132. </tr>
  133. <tr>
  134. <td valign="top">password</td>
  135. <td valign="top">The password.</td>
  136. <td valign="top" align="center">Not if you are using key based
  137. authentication or the password has been given in the file or
  138. todir attribute.</td>
  139. </tr>
  140. <tr>
  141. <td valign="top">keyfile</td>
  142. <td valign="top">Location of the file holding the private key.</td>
  143. <td valign="top" align="center">Yes, if you are using key based
  144. authentication.</td>
  145. </tr>
  146. <tr>
  147. <td valign="top">passphrase</td>
  148. <td valign="top">Passphrase for your private key.</td>
  149. <td valign="top" align="center">No, defaults to an empty string.</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">verbose</td>
  153. <td valign="top">Determines whether SCP outputs verbosely to the
  154. user. Currently this means outputting dots/stars showing the
  155. progress of a file transfer. <em>since Ant 1.6.2</em></td>
  156. <td valign="top" align="center">No; defaults to false.</td>
  157. </tr>
  158. <tr>
  159. <td valign="top">sftp</td>
  160. <td valign="top">Determines whether SCP uses the sftp protocol.
  161. The sftp protocol is the file transfer protocol of SSH2. It is
  162. recommended that this be set to true if you are copying to/from a
  163. server that doesn't support scp1. <em>since Ant 1.7</em></td>
  164. <td valign="top" align="center">No; defaults to false.</td>
  165. </tr>
  166. <tr>
  167. <td valign="top">preserveLastModified</td>
  168. <td valign="top">Determines whether the last modification
  169. timestamp of downloaded files is preserved. It only works when
  170. transferring from a remote to a local system and probably doesn't
  171. work with a server that doesn't support SSH2. <em>since Ant
  172. 1.8.0</em></td>
  173. <td valign="top" align="center">No; defaults to false.</td>
  174. </tr>
  175. </table>
  176. <h3>Parameters specified as nested elements</h3>
  177. <h4>fileset</h4>
  178. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
  179. sets of files to copy.
  180. To use a fileset, the <code>todir</code> attribute must be set.</p>
  181. <h3>Examples</h3>
  182. <p><b>Copy a single local file to a remote machine</b></p>
  183. <pre>
  184. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user:password@somehost:/home/chuck&quot;/&gt;
  185. </pre>
  186. <p><b>Copy a single local file to a remote machine with separate
  187. password attribute</b></p>
  188. <pre>
  189. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user@somehost:/home/chuck&quot; password=&quot;password&quot;/&gt;
  190. </pre>
  191. <p><b>Copy a single local file to a remote machine using key base
  192. authentication.</b></p>
  193. <pre>
  194. &lt;scp file=&quot;myfile.txt&quot;
  195. todir=&quot;user@somehost:/home/chuck&quot;
  196. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  197. passphrase=&quot;my extremely secret passphrase&quot;
  198. /&gt;
  199. </pre>
  200. <p><b>Copy a single remote file to a local directory</b></p>
  201. <pre>
  202. &lt;scp file=&quot;user:password@somehost:/home/chuck/myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
  203. </pre>
  204. <p><b>Copy a remote directory to a local directory</b></p>
  205. <pre>
  206. &lt;scp file=&quot;user:password@somehost:/home/chuck/*&quot; todir=&quot;/home/sara&quot;/&gt;
  207. </pre>
  208. <p><b>Copy a local directory to a remote directory</b></p>
  209. <pre>
  210. &lt;scp todir=&quot;user:password@somehost:/home/chuck/&quot;&gt;
  211. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  212. &lt;/scp&gt;
  213. </pre>
  214. <p><b>Copy a set of files to a directory</b></p>
  215. <pre>
  216. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  217. &lt;fileset dir=&quot;src_dir&quot;&gt;
  218. &lt;include name=&quot;**/*.java&quot;/&gt;
  219. &lt;/fileset&gt;
  220. &lt;/scp&gt;
  221. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  222. &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
  223. &lt;/scp&gt;
  224. </pre>
  225. <p><strong>Security Note:</strong> Hard coding passwords and/or usernames
  226. in scp task can be a serious security hole. Consider using variable
  227. substitution and include the password on the command line. For example:
  228. <p>
  229. <pre>
  230. &lt;scp todir=&quot;${username}:${password}@host:/dir&quot; ...&gt;
  231. </pre>
  232. Invoking ant with the following command line:
  233. <pre>
  234. ant -Dusername=me -Dpassword=mypassword target1 target2
  235. </pre>
  236. Is slightly better, but the username/password is exposed to all users on an Unix
  237. system (via the ps command). The best approach is to use the
  238. <code>&lt;input&gt;</code> task and/or retrieve the password from a (secured)
  239. .properties file.
  240. <p>
  241. <p><strong>Unix Note:</strong> File permissions are not retained when files
  242. are copied; they end up with the default <code>UMASK</code> permissions
  243. instead. This is caused by the lack of any means to query or set file
  244. permissions in the current Java runtimes. If you need a permission-
  245. preserving copy function, use <code>&lt;exec executable="scp" ... &gt;</code>
  246. instead.
  247. </p>
  248. </body>
  249. </html>