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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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></td>
  27. <td valign="top" align="center">Yes, unless a nested
  28. <code>&lt;fileset&gt;</code> element is used.</td>
  29. </tr>
  30. <tr>
  31. <td valign="top">todir</td>
  32. <td valign="top">The directory to copy to. This can be a local path
  33. or a remote path of the form <i>user:password@host:/directory/path</i></td>
  34. <td valian="top" align="center">Yes</td>
  35. </tr>
  36. <tr>
  37. <td valign="top">port</td>
  38. <td valign="top">The port to connect to on the remote host.</td>
  39. <td valian="top" align="center">No, defaults to 22.</td>
  40. </tr>
  41. <tr>
  42. <td valign="top">trust</td>
  43. <td valign="top">This trusts all unknown hosts if set to yes/true.</td>
  44. <td valian="top" align="center">No, defaults to No.</td>
  45. </tr>
  46. <tr>
  47. <td valign="top">knownhosts</td>
  48. <td valign="top">This sets the known hosts file to use to validate
  49. the identity of the remote host. This must be a SSH2 format file.
  50. SSH1 format is not supported.</td>
  51. <td valian="top" align="center">No, defaults to
  52. ${user.home}/.ssh/known_hosts.</td>
  53. </tr>
  54. <tr>
  55. <td valign="top">failonerror</td>
  56. <td valign="top">Log a warning message, but do not stop the build,
  57. when the transfer does not work.
  58. </td>
  59. <td valign="top" align="center">No; defaults to true.</td>
  60. </tr>
  61. </table>
  62. <h3>Parameters specified as nested elements</h3>
  63. <h4>fileset</h4>
  64. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
  65. sets of files to copy.
  66. To use a fileset, the <code>todir</code> attribute must be set.</p>
  67. <h3>Examples</h3>
  68. <p><b>Copy a single local file to a remote machine</b></p>
  69. <pre>
  70. &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user:password@somehost:/home/chuck&quot;/&gt;
  71. </pre>
  72. <p><b>Copy a single remote file to a local directory</b></p>
  73. <pre>
  74. &lt;scp file=&quot;user:password@somehost:/home/chuck/myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
  75. </pre>
  76. <p><b>Copy a remote directory to a local directory</b></p>
  77. <pre>
  78. &lt;scp file=&quot;user:password@somehost:/home/chuck/*&quot; todir=&quot;/home/sara&quot; /&gt;
  79. </pre>
  80. <p><b>Copy a local directory to a remote directory</b></p>
  81. <pre>
  82. &lt;scp todir=&quot;user:password@somehost:/home/chuck/&quot;&gt;
  83. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  84. &lt;/scp&gt;
  85. </pre>
  86. <p><b>Copy a set of files to a directory</b></p>
  87. <pre>
  88. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  89. &lt;fileset dir=&quot;src_dir&quot;&gt;
  90. &lt;include name=&quot;**/*.java&quot;/&gt;
  91. &lt;/fileset&gt;
  92. &lt;/scp&gt;
  93. &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
  94. &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
  95. &lt;/scp&gt;
  96. </pre>
  97. <p><strong>Security Note:</strong> Hard coding passwords and/or usernames
  98. in scp task can be a serious security hole. Consider using variable
  99. substituion and include the password on the command line. For example:<br>
  100. <pre>
  101. &lt;scp todir=&quot;${username}:${password}@host:/dir&quot; ...&gt;
  102. </pre>
  103. Invoke ant with the following command line:
  104. <pre>
  105. ant -Dusername=me -Dpassword=mypassword target1 target2
  106. </pre>
  107. </p>
  108. <p><strong>Unix Note:</strong> File permissions are not retained when files
  109. are copied; they end up with the default <code>UMASK</code> permissions
  110. instead. This is caused by the lack of any means to query or set file
  111. permissions in the current Java runtimes. If you need a permission-
  112. preserving copy function, use <code>&lt;exec executable="scp" ... &gt;</code>
  113. instead.
  114. </p>
  115. <hr><p align="center">Copyright &copy; 2003 Apache Software Foundation.
  116. All rights Reserved.</p>
  117. </body>
  118. </html>