source: release-kits/lirk3/bin/ant-installer/web/manual/manual/OptionalTasks/scp.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 10.1 KB
Line 
1<!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<html>
18
19<head>
20<meta http-equiv="Content-Language" content="en-us">
21<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22<title>SCP Task</title>
23</head>
24
25<body>
26
27<h2><a name="scp">SCP</a></h2>
28<h3>Description</h3>
29
30<p><em>since Ant 1.6</em></p>
31
32<p>Copies a file or FileSet to or from a (remote) machine running an SSH daemon.
33FileSet <i>only</i> works for copying files from the local machine to a
34remote machine.</p>
35
36<p><b>Note:</b> This task depends on external libraries not included
37in the Ant distribution. See <a
38href="../install.html#librarydependencies">Library Dependencies</a>
39for more information. This task has been tested with jsch-0.1.2 and later.</p>
40
41<p>See also the <a href="scp.html">scp task</a></p>
42
43<h3>Parameters</h3>
44<table border="1" cellpadding="2" cellspacing="0">
45 <tr>
46 <td valign="top"><b>Attribute</b></td>
47 <td valign="top"><b>Description</b></td>
48 <td align="center" valign="top"><b>Required</b></td>
49 </tr>
50 <tr>
51 <td valign="top">file</td>
52 <td valign="top">The file to copy. This can be a local path or a
53 remote path of the form <i>user[:password]@host:/directory/path</i>.
54 <i>:password</i> can be omitted if you use key based
55 authentication or specify the password attribute. The way remote
56 path is recognized is whether it contains @ character or not. This
57 will not work if your localPath contains @ character.</td>
58 <td valign="top" align="center">Yes, unless a nested
59 <code>&lt;fileset&gt;</code> element is used.</td>
60 </tr>
61 <tr>
62 <td valign="top">localFile</td>
63 <td valign="top">This is an alternative to the file attribute. But
64 this must always point to a local file. The reason this was added
65 was that when you give file attribute it is treated as remote if
66 it contains @ character. This character can exist also in local
67 paths. <em>since Ant 1.6.2</em></td>
68 <td valign="top" align="center">Alternative to file attribute.</td>
69 </tr>
70 <tr>
71 <td valign="top">remoteFile</td>
72 <td valign="top">This is an alternative to the file attribute. But
73 this must always point to a remote file. <em>since Ant 1.6.2</em></td>
74 <td valign="top" align="center">Alternative to file attribute.</td>
75 </tr>
76 <tr>
77 <td valign="top">todir</td>
78 <td valign="top">The directory to copy to. This can be a local path
79 or a remote path of the form <i>user[:password]@host:/directory/path</i>.
80 <i>:password</i> can be omitted if you use key based
81 authentication or specify the password attribute. The way remote
82 path is recognized is whether it contains @ character or not. This
83 will not work if your localPath contains @ character.</td>
84 <td valian="top" align="center">Yes</td>
85 </tr>
86 <tr>
87 <td valign="top">localTodir</td>
88 <td valign="top">This is an alternative to the todir
89 attribute. But this must always point to a local directory. The
90 reason this was added was that when you give todir attribute it is
91 treated as remote if it contains @ character. This character can
92 exist also in local paths. <em>since Ant 1.6.2</em></td>
93 <td valian="top" align="center">Alternative to todir attribute.</td>
94 </tr>
95 <tr>
96 <td valign="top">localTofile</td>
97 <td valign="top">Changes the file name to the given name while
98 receiving it, only useful if receiving a single file. <em>since
99 Ant 1.6.2</em></td>
100 <td valian="top" align="center">Alternative to todir attribute.</td>
101 </tr>
102 <tr>
103 <td valign="top">remoteTodir</td>
104 <td valign="top">This is an alternative to the todir
105 attribute. But this must always point to a remote directory.
106 <em>since Ant 1.6.2</em></td>
107 <td valian="top" align="center">Alternative to todir attribute.</td>
108 </tr>
109 <tr>
110 <td valign="top">remoteTofile</td>
111 <td valign="top">Changes the file name to the given name while
112 sending it, only useful if sending a single file. <em>since
113 Ant 1.6.2</em></td>
114 <td valian="top" align="center">Alternative to todir attribute.</td>
115 </tr>
116 <tr>
117 <td valign="top">port</td>
118 <td valign="top">The port to connect to on the remote host.</td>
119 <td valian="top" align="center">No, defaults to 22.</td>
120 </tr>
121 <tr>
122 <td valign="top">trust</td>
123 <td valign="top">This trusts all unknown hosts if set to yes/true.<br>
124 <strong>Note</strong> If you set this to false (the default), the
125 host you connect to must be listed in your knownhosts file, this
126 also implies that the file exists.</td>
127 <td valian="top" align="center">No, defaults to No.</td>
128 </tr>
129 <tr>
130 <td valign="top">knownhosts</td>
131 <td valign="top">This sets the known hosts file to use to validate
132 the identity of the remote host. This must be a SSH2 format file.
133 SSH1 format is not supported.</td>
134 <td valian="top" align="center">No, defaults to
135 ${user.home}/.ssh/known_hosts.</td>
136 </tr>
137 <tr>
138 <td valign="top">failonerror</td>
139 <td valign="top">Whether to halt the build if the transfer fails.
140 </td>
141 <td valign="top" align="center">No; defaults to true.</td>
142 </tr>
143 <tr>
144 <td valign="top">password</td>
145 <td valign="top">The password.</td>
146 <td valign="top" align="center">Not if you are using key based
147 authentication or the password has been given in the file or
148 todir attribute.</td>
149 </tr>
150 <tr>
151 <td valign="top">keyfile</td>
152 <td valign="top">Location of the file holding the private key.</td>
153 <td valign="top" align="center">Yes, if you are using key based
154 authentication.</td>
155 </tr>
156 <tr>
157 <td valign="top">passphrase</td>
158 <td valign="top">Passphrase for your private key.</td>
159 <td valign="top" align="center">Yes, if you are using key based
160 authentication.</td>
161 </tr>
162 <tr>
163 <td valign="top">verbose</td>
164 <td valign="top">Determines whether SCP outputs verbosely to the
165 user. Currently this means outputting dots/stars showing the
166 progress of a file transfer. <em>since Ant 1.6.2</em></td>
167 <td valign="top" align="center">No; defaults to false.</td>
168 </tr>
169 <tr>
170 <td valign="top">sftp</td>
171 <td valign="top">Determines whether SCP uses the sftp protocol.
172 The sftp protocol is the file transfer protocol of SSH2. It is
173 recommended that this be set to true if you are copying to/from a
174 server that doesn't support scp1. <em>since Ant 1.7</em></td>
175 <td valign="top" align="center">No; defaults to false.</td>
176 </tr>
177</table>
178<h3>Parameters specified as nested elements</h3>
179
180<h4>fileset</h4>
181 <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
182sets of files to copy.
183 To use a fileset, the <code>todir</code> attribute must be set.</p>
184
185<h3>Examples</h3>
186<p><b>Copy a single local file to a remote machine</b></p>
187<pre>
188 &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user:password@somehost:/home/chuck&quot;/&gt;
189</pre>
190
191<p><b>Copy a single local file to a remote machine with separate
192password attribute</b></p>
193<pre>
194 &lt;scp file=&quot;myfile.txt&quot; todir=&quot;user@somehost:/home/chuck&quot; password=&quot;password&quot;/&gt;
195</pre>
196
197<p><b>Copy a single local file to a remote machine using key base
198authentication.</b></p>
199<pre>
200 &lt;scp file=&quot;myfile.txt&quot;
201 todir=&quot;user@somehost:/home/chuck&quot;
202 keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
203 passphrase=&quot;my extremely secret passphrase&quot;
204 /&gt;
205</pre>
206
207<p><b>Copy a single remote file to a local directory</b></p>
208<pre>
209 &lt;scp file=&quot;user:password@somehost:/home/chuck/myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
210</pre>
211
212<p><b>Copy a remote directory to a local directory</b></p>
213<pre>
214 &lt;scp file=&quot;user:password@somehost:/home/chuck/*&quot; todir=&quot;/home/sara&quot;/&gt;
215</pre>
216
217<p><b>Copy a local directory to a remote directory</b></p>
218<pre>
219 &lt;scp todir=&quot;user:password@somehost:/home/chuck/&quot;&gt;
220 &lt;fileset dir=&quot;src_dir&quot;/&gt;
221 &lt;/scp&gt;
222</pre>
223<p><b>Copy a set of files to a directory</b></p>
224<pre>
225 &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
226 &lt;fileset dir=&quot;src_dir&quot;&gt;
227 &lt;include name=&quot;**/*.java&quot;/&gt;
228 &lt;/fileset&gt;
229 &lt;/scp&gt;
230
231 &lt;scp todir=&quot;user:password@somehost:/home/chuck&quot;&gt;
232 &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
233 &lt;/scp&gt;
234</pre>
235
236<p><strong>Security Note:</strong> Hard coding passwords and/or usernames
237in scp task can be a serious security hole. Consider using variable
238substitution and include the password on the command line. For example:
239<p>
240<pre>
241 &lt;scp todir=&quot;${username}:${password}@host:/dir&quot; ...&gt;
242</pre>
243Invoking ant with the following command line:
244<pre>
245 ant -Dusername=me -Dpassword=mypassword target1 target2
246</pre>
247
248Is slightly better, but the username/password is exposed to all users on an Unix
249system (via the ps command). The best approach is to use the
250<code>&lt;input&gt;</code> task and/or retrieve the password from a (secured)
251.properties file.
252
253<p>
254
255<p><strong>Unix Note:</strong> File permissions are not retained when files
256are copied; they end up with the default <code>UMASK</code> permissions
257instead. This is caused by the lack of any means to query or set file
258permissions in the current Java runtimes. If you need a permission-
259preserving copy function, use <code>&lt;exec executable="scp" ... &gt;</code>
260instead.
261</p>
262
263
264
265</body>
266</html>
267
Note: See TracBrowser for help on using the repository browser.