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