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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.9.</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.</td>
  31. <td valign="top" align="center">Yes, unless a nested
  32. <code>&lt;fileset&gt;</code> element is used.</td>
  33. </tr>
  34. <tr>
  35. <td valign="top">todir</td>
  36. <td valign="top">The directory to copy to. This can be a local path
  37. or a remote path of the form <i>user[:password]@host:/directory/path</i>.
  38. <i>:password</i> can be ommitted if you use key based
  39. authentication or specify the password attribute.</td>
  40. <td valian="top" align="center">Yes</td>
  41. </tr>
  42. <tr>
  43. <td valign="top">port</td>
  44. <td valign="top">The port to connect to on the remote host.</td>
  45. <td valian="top" align="center">No, defaults to 22.</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">trust</td>
  49. <td valign="top">This trusts all unknown hosts if set to yes/true.<br>
  50. <strong>Note</strong> If you set this to false (the default), the
  51. host you connect to must be listed in your knownhosts file, this
  52. also implies that the file exists.</td>
  53. <td valian="top" align="center">No, defaults to No.</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">knownhosts</td>
  57. <td valign="top">This sets the known hosts file to use to validate
  58. the identity of the remote host. This must be a SSH2 format file.
  59. SSH1 format is not supported.</td>
  60. <td valian="top" align="center">No, defaults to
  61. ${user.home}/.ssh/known_hosts.</td>
  62. </tr>
  63. <tr>
  64. <td valign="top">failonerror</td>
  65. <td valign="top">Whether to halt the build if the transfer fails.
  66. </td>
  67. <td valign="top" align="center">No; defaults to true.</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">password</td>
  71. <td valign="top">The password.</td>
  72. <td valign="top" align="center">Not if you are using key based
  73. authentication or the password has been given in the file or
  74. todir attribute.</td>
  75. </tr>
  76. <tr>
  77. <td valign="top">keyfile</td>
  78. <td valign="top">Location of the file holding the private key.</td>
  79. <td valign="top" align="center">Yes, if you are using key based
  80. authentication.</td>
  81. </tr>
  82. <tr>
  83. <td valign="top">passphrase</td>
  84. <td valign="top">Passphrase for your private key.</td>
  85. <td valign="top" align="center">Yes, if you are using key based
  86. authentication.</td>
  87. </tr>
  88. </table>
  89. <h3>Parameters specified as nested elements</h3>
  90. <h4>fileset</h4>
  91. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
  92. sets of files to copy.
  93. To use a fileset, the <code>todir</code> attribute must be set.</p>
  94. <h3>Examples</h3>
  95. <p><b>Copy a single local file to a remote machine</b></p>
  96. <pre>
  97. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user:password@somehost:/home/chuck&quot;/&gt;
  98. </pre>
  99. <p><b>Copy a single local file to a remote machine with separate
  100. password attribute</b></p>
  101. <pre>
  102. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user@somehost:/home/chuck&quot; password=&quot;password&quot;/&gt;
  103. </pre>
  104. <p><b>Copy a single local file to a remote machine using key base
  105. authentication.</b></p>
  106. <pre>
  107. &lt;scp file=&quot;myfile.txt&quot;
  108. todir=&quot;user@somehost:/home/chuck&quot;
  109. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  110. passphrase=&quot;my extremely secret passphrase&quot;
  111. /&gt;
  112. </pre>
  113. <p><b>Copy a single remote file to a local directory</b></p>
  114. <pre>
  115. &lt;scp file=&quot;user:password@somehost:/home/chuck/myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
  116. </pre>
  117. <p><b>Copy a remote directory to a local directory</b></p>
  118. <pre>
  119. &lt;scp file=&quot;user:password@somehost:/home/chuck/*&quot; todir=&quot;/home/sara&quot; /&gt;
  120. </pre>
  121. <p><b>Copy a local directory to a remote directory</b></p>
  122. <pre>
  123. &lt;scp todir=&quot;user:password@somehost:/home/chuck/&quot;&gt;
  124. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  125. &lt;/scp&gt;
  126. </pre>
  127. <p><b>Copy a set of files to a directory</b></p>
  128. <pre>
  129. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  130. &lt;fileset dir=&quot;src_dir&quot;&gt;
  131. &lt;include name=&quot;**/*.java&quot;/&gt;
  132. &lt;/fileset&gt;
  133. &lt;/scp&gt;
  134. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  135. &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
  136. &lt;/scp&gt;
  137. </pre>
  138. <p><strong>Security Note:</strong> Hard coding passwords and/or usernames
  139. in scp task can be a serious security hole. Consider using variable
  140. substituion and include the password on the command line. For example:<br>
  141. <pre>
  142. &lt;scp todir=&quot;${username}:${password}@host:/dir&quot; ...&gt;
  143. </pre>
  144. Invoke ant with the following command line:
  145. <pre>
  146. ant -Dusername=me -Dpassword=mypassword target1 target2
  147. </pre>
  148. </p>
  149. <p><strong>Unix Note:</strong> File permissions are not retained when files
  150. are copied; they end up with the default <code>UMASK</code> permissions
  151. instead. This is caused by the lack of any means to query or set file
  152. permissions in the current Java runtimes. If you need a permission-
  153. preserving copy function, use <code>&lt;exec executable="scp" ... &gt;</code>
  154. instead.
  155. </p>
  156. <hr><p align="center">Copyright &copy; 2003 Apache Software Foundation.
  157. All rights Reserved.</p>
  158. </body>
  159. </html>