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

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