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 kB

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