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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 omitted 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 omitted 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">localTofile</td>
  72. <td valign="top">Changes the file name to the given name while
  73. receiving it, only useful if receiving a single file. <em>since
  74. 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">remoteTodir</td>
  79. <td valign="top">This is an alternative to the todir
  80. attribute. But this must always point to a remote directory.
  81. <em>since Ant 1.6.2</em></td>
  82. <td valian="top" align="center">Alternative to todir attribute.</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">remoteTofile</td>
  86. <td valign="top">Changes the file name to the given name while
  87. sending it, only useful if sending a single file. <em>since
  88. Ant 1.6.2</em></td>
  89. <td valian="top" align="center">Alternative to todir attribute.</td>
  90. </tr>
  91. <tr>
  92. <td valign="top">port</td>
  93. <td valign="top">The port to connect to on the remote host.</td>
  94. <td valian="top" align="center">No, defaults to 22.</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">trust</td>
  98. <td valign="top">This trusts all unknown hosts if set to yes/true.<br>
  99. <strong>Note</strong> If you set this to false (the default), the
  100. host you connect to must be listed in your knownhosts file, this
  101. also implies that the file exists.</td>
  102. <td valian="top" align="center">No, defaults to No.</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">knownhosts</td>
  106. <td valign="top">This sets the known hosts file to use to validate
  107. the identity of the remote host. This must be a SSH2 format file.
  108. SSH1 format is not supported.</td>
  109. <td valian="top" align="center">No, defaults to
  110. ${user.home}/.ssh/known_hosts.</td>
  111. </tr>
  112. <tr>
  113. <td valign="top">failonerror</td>
  114. <td valign="top">Whether to halt the build if the transfer fails.
  115. </td>
  116. <td valign="top" align="center">No; defaults to true.</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">password</td>
  120. <td valign="top">The password.</td>
  121. <td valign="top" align="center">Not if you are using key based
  122. authentication or the password has been given in the file or
  123. todir attribute.</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">keyfile</td>
  127. <td valign="top">Location of the file holding the private key.</td>
  128. <td valign="top" align="center">Yes, if you are using key based
  129. authentication.</td>
  130. </tr>
  131. <tr>
  132. <td valign="top">passphrase</td>
  133. <td valign="top">Passphrase for your private key.</td>
  134. <td valign="top" align="center">Yes, if you are using key based
  135. authentication.</td>
  136. </tr>
  137. <tr>
  138. <td valign="top">verbose</td>
  139. <td valign="top">Determines whether SCP outputs verbosely to the
  140. user. Currently this means outputting dots/stars showing the
  141. progress of a file transfer. <em>since Ant 1.6.2</em></td>
  142. <td valign="top" align="center">No; defaults to false.</td>
  143. </tr>
  144. </table>
  145. <h3>Parameters specified as nested elements</h3>
  146. <h4>fileset</h4>
  147. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
  148. sets of files to copy.
  149. To use a fileset, the <code>todir</code> attribute must be set.</p>
  150. <h3>Examples</h3>
  151. <p><b>Copy a single local file to a remote machine</b></p>
  152. <pre>
  153. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user:password@somehost:/home/chuck&quot;/&gt;
  154. </pre>
  155. <p><b>Copy a single local file to a remote machine with separate
  156. password attribute</b></p>
  157. <pre>
  158. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user@somehost:/home/chuck&quot; password=&quot;password&quot;/&gt;
  159. </pre>
  160. <p><b>Copy a single local file to a remote machine using key base
  161. authentication.</b></p>
  162. <pre>
  163. &lt;scp file=&quot;myfile.txt&quot;
  164. todir=&quot;user@somehost:/home/chuck&quot;
  165. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  166. passphrase=&quot;my extremely secret passphrase&quot;
  167. /&gt;
  168. </pre>
  169. <p><b>Copy a single remote file to a local directory</b></p>
  170. <pre>
  171. &lt;scp file=&quot;user:password@somehost:/home/chuck/myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
  172. </pre>
  173. <p><b>Copy a remote directory to a local directory</b></p>
  174. <pre>
  175. &lt;scp file=&quot;user:password@somehost:/home/chuck/*&quot; todir=&quot;/home/sara&quot;/&gt;
  176. </pre>
  177. <p><b>Copy a local directory to a remote directory</b></p>
  178. <pre>
  179. &lt;scp todir=&quot;user:password@somehost:/home/chuck/&quot;&gt;
  180. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  181. &lt;/scp&gt;
  182. </pre>
  183. <p><b>Copy a set of files to a directory</b></p>
  184. <pre>
  185. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  186. &lt;fileset dir=&quot;src_dir&quot;&gt;
  187. &lt;include name=&quot;**/*.java&quot;/&gt;
  188. &lt;/fileset&gt;
  189. &lt;/scp&gt;
  190. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  191. &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
  192. &lt;/scp&gt;
  193. </pre>
  194. <p><strong>Security Note:</strong> Hard coding passwords and/or usernames
  195. in scp task can be a serious security hole. Consider using variable
  196. substitution and include the password on the command line. For example:<br>
  197. <pre>
  198. &lt;scp todir=&quot;${username}:${password}@host:/dir&quot; ...&gt;
  199. </pre>
  200. Invoke ant with the following command line:
  201. <pre>
  202. ant -Dusername=me -Dpassword=mypassword target1 target2
  203. </pre>
  204. </p>
  205. <p><strong>Unix Note:</strong> File permissions are not retained when files
  206. are copied; they end up with the default <code>UMASK</code> permissions
  207. instead. This is caused by the lack of any means to query or set file
  208. permissions in the current Java runtimes. If you need a permission-
  209. preserving copy function, use <code>&lt;exec executable="scp" ... &gt;</code>
  210. instead.
  211. </p>
  212. <hr><p align="center">Copyright &copy; 2003-2004 The Apache Software Foundation.
  213. All rights Reserved.</p>
  214. </body>
  215. </html>