OSDN Git Service

Change OpenSSL context mode flags.
[ffftp/ffftp.git] / putty / DOC / PSCP.BUT
1 \define{versionidpscp} \versionid $Id: pscp.but 9366 2011-12-10 12:08:09Z simon $\r
2 \r
3 \#FIXME: Need examples\r
4 \r
5 \C{pscp} Using \i{PSCP} to transfer files securely\r
6 \r
7 \i{PSCP}, the PuTTY Secure Copy client, is a tool for \i{transferring files}\r
8 securely between computers using an SSH connection.\r
9 \r
10 If you have an SSH-2 server, you might prefer PSFTP (see \k{psftp})\r
11 for interactive use. PSFTP does not in general work with SSH-1\r
12 servers, however.\r
13 \r
14 \H{pscp-starting} Starting PSCP\r
15 \r
16 PSCP is a command line application.  This means that you cannot just\r
17 double-click on its icon to run it and instead you have to bring up a\r
18 \i{console window}.  With Windows 95, 98, and ME, this is called an\r
19 \q{MS-DOS Prompt} and with Windows NT, 2000, and XP, it is called a\r
20 \q{Command Prompt}.  It should be available from the Programs section\r
21 of your \i{Start Menu}.\r
22 \r
23 To start PSCP it will need either to be on your \i{\c{PATH}} or in your\r
24 current directory.  To add the directory containing PSCP to your\r
25 \c{PATH} environment variable, type into the console window:\r
26 \r
27 \c set PATH=C:\path\to\putty\directory;%PATH%\r
28 \r
29 This will only work for the lifetime of that particular console\r
30 window.  To set your \c{PATH} more permanently on Windows NT, 2000,\r
31 and XP, use the Environment tab of the System Control Panel.  On\r
32 Windows 95, 98, and ME, you will need to edit your \i\c{AUTOEXEC.BAT}\r
33 to include a \c{set} command like the one above.\r
34 \r
35 \H{pscp-usage} PSCP Usage\r
36 \r
37 Once you've got a console window to type into, you can just type\r
38 \c{pscp} on its own to bring up a usage message.  This tells you the\r
39 version of PSCP you're using, and gives you a brief summary of how to\r
40 use PSCP:\r
41 \r
42 \c Z:\owendadmin>pscp\r
43 \c PuTTY Secure Copy client\r
44 \c Release 0.62\r
45 \c Usage: pscp [options] [user@]host:source target\r
46 \c        pscp [options] source [source...] [user@]host:target\r
47 \c        pscp [options] -ls [user@]host:filespec\r
48 \c Options:\r
49 \c   -V        print version information and exit\r
50 \c   -pgpfp    print PGP key fingerprints and exit\r
51 \c   -p        preserve file attributes\r
52 \c   -q        quiet, don't show statistics\r
53 \c   -r        copy directories recursively\r
54 \c   -v        show verbose messages\r
55 \c   -load sessname  Load settings from saved session\r
56 \c   -P port   connect to specified port\r
57 \c   -l user   connect with specified username\r
58 \c   -pw passw login with specified password\r
59 \c   -1 -2     force use of particular SSH protocol version\r
60 \c   -4 -6     force use of IPv4 or IPv6\r
61 \c   -C        enable compression\r
62 \c   -i key    private key file for authentication\r
63 \c   -noagent  disable use of Pageant\r
64 \c   -agent    enable use of Pageant\r
65 \c   -batch    disable all interactive prompts\r
66 \c   -unsafe   allow server-side wildcards (DANGEROUS)\r
67 \c   -sftp     force use of SFTP protocol\r
68 \c   -scp      force use of SCP protocol\r
69 \r
70 (PSCP's interface is much like the Unix \c{scp} command, if you're\r
71 familiar with that.)\r
72 \r
73 \S{pscp-usage-basics} The basics\r
74 \r
75 To \I{receiving files}receive (a) file(s) from a remote server: \r
76 \r
77 \c pscp [options] [user@]host:source target\r
78 \r
79 So to copy the file \c{/etc/hosts} from the server \c{example.com} as\r
80 user \c{fred} to the file \c{c:\\temp\\example-hosts.txt}, you would type:\r
81 \r
82 \c pscp fred@example.com:/etc/hosts c:\temp\example-hosts.txt\r
83 \r
84 To \I{sending files}send (a) file(s) to a remote server: \r
85 \r
86 \c pscp [options] source [source...] [user@]host:target\r
87 \r
88 So to copy the local file \c{c:\\documents\\foo.txt} to the server\r
89 \c{example.com} as user \c{fred} to the file \c{/tmp/foo} you would\r
90 type:\r
91 \r
92 \c pscp c:\documents\foo.txt fred@example.com:/tmp/foo\r
93 \r
94 You can use \i{wildcards} to transfer multiple files in either\r
95 direction, like this:\r
96 \r
97 \c pscp c:\documents\*.doc fred@example.com:docfiles\r
98 \c pscp fred@example.com:source/*.c c:\source\r
99 \r
100 However, in the second case (using a wildcard for multiple remote\r
101 files) you may see a warning saying something like \q{warning:\r
102 remote host tried to write to a file called \cq{terminal.c} when we\r
103 requested a file called \cq{*.c}. If this is a wildcard, consider\r
104 upgrading to SSH-2 or using the \cq{-unsafe} option. Renaming of\r
105 this file has been disallowed}.\r
106 \r
107 This is due to a \I{security risk}fundamental insecurity in the old-style\r
108 \i{SCP protocol}: the client sends the wildcard string (\c{*.c}) to the\r
109 server, and the server sends back a sequence of file names that\r
110 match the wildcard pattern. However, there is nothing to stop the\r
111 server sending back a \e{different} pattern and writing over one of\r
112 your other files: if you request \c{*.c}, the server might send back\r
113 the file name \c{AUTOEXEC.BAT} and install a virus for you. Since\r
114 the wildcard matching rules are decided by the server, the client\r
115 cannot reliably verify that the filenames sent back match the\r
116 pattern.\r
117 \r
118 PSCP will attempt to use the newer \i{SFTP} protocol (part of SSH-2)\r
119 where possible, which does not suffer from this security flaw. If\r
120 you are talking to an SSH-2 server which supports SFTP, you will\r
121 never see this warning. (You can force use of the SFTP protocol,\r
122 if available, with \c{-sftp} - see \k{pscp-usage-options-backend}.)\r
123 \r
124 If you really need to use a server-side wildcard with an SSH-1\r
125 server, you can use the \i\c{-unsafe} command line option with PSCP:\r
126 \r
127 \c pscp -unsafe fred@example.com:source/*.c c:\source\r
128 \r
129 This will suppress the warning message and the file transfer will\r
130 happen. However, you should be aware that by using this option you\r
131 are giving the server the ability to write to \e{any} file in the\r
132 target directory, so you should only use this option if you trust\r
133 the server administrator not to be malicious (and not to let the\r
134 server machine be cracked by malicious people). Alternatively, do\r
135 any such download in a newly created empty directory. (Even in\r
136 \q{unsafe} mode, PSCP will still protect you against the server\r
137 trying to get out of that directory using pathnames including\r
138 \cq{..}.)\r
139 \r
140 \S2{pscp-usage-basics-user} \c{user}\r
141 \r
142 The \i{login name} on the remote server. If this is omitted, and \c{host}\r
143 is a PuTTY saved session, PSCP will use any username specified by that \r
144 saved session.  Otherwise, PSCP will attempt to use the local Windows\r
145 username.\r
146 \r
147 \S2{pscp-usage-basics-host} \I{hostname}\c{host}\r
148 \r
149 The name of the remote server, or the name of an existing PuTTY saved\r
150 session. In the latter case, the session's settings for hostname, port\r
151 number, cipher type and username will be used.\r
152 \r
153 \S2{pscp-usage-basics-source} \c{source}\r
154 \r
155 One or more source files. \ii{Wildcards} are allowed.  The syntax of\r
156 wildcards depends on the system to which they apply, so if you are\r
157 copying \e{from} a Windows system \e{to} a UNIX system, you should use \r
158 Windows wildcard syntax (e.g. \c{*.*}), but if you are copying \e{from} \r
159 a UNIX system \e{to} a Windows system, you would use the wildcard\r
160 syntax allowed by your UNIX shell (e.g. \c{*}).\r
161 \r
162 If the source is a remote server and you do not specify a full\r
163 pathname (in UNIX, a pathname beginning with a \c{/} (slash)\r
164 character), what you specify as a source will be interpreted relative\r
165 to your \i{home directory} on the remote server.\r
166 \r
167 \S2{pscp-usage-basics-target} \c{target}\r
168 \r
169 The filename or directory to put the file(s).  When copying from a\r
170 remote server to a local host, you may wish simply to place the\r
171 file(s) in the current directory.  To do this, you should specify a\r
172 target of \c{.}.  For example:\r
173 \r
174 \c pscp fred@example.com:/home/tom/.emacs .\r
175 \r
176 ...would copy \c{/home/tom/.emacs} on the remote server to the current \r
177 directory.\r
178 \r
179 As with the \c{source} parameter, if the target is on a remote server\r
180 and is not a full path name, it is interpreted relative to your home\r
181 directory on the remote server.\r
182 \r
183 \S{pscp-usage-options} Options\r
184 \r
185 PSCP accepts all the general command line options supported by the\r
186 PuTTY tools, except the ones which make no sense in a file transfer\r
187 utility. See \k{using-general-opts} for a description of these\r
188 options. (The ones not supported by PSCP are clearly marked.)\r
189 \r
190 PSCP also supports some of its own options. The following sections\r
191 describe PSCP's specific command-line options.\r
192 \r
193 \S2{pscp-usage-options-ls}\I{-ls-PSCP}\c{-ls} \I{listing files}list remote files\r
194 \r
195 If the \c{-ls} option is given, no files are transferred; instead,\r
196 remote files are listed. Only a hostname specification and\r
197 optional remote file specification need be given. For example:\r
198 \r
199 \c pscp -ls fred@example.com:dir1\r
200 \r
201 The SCP protocol does not contain within itself a means of listing\r
202 files. If SCP is in use, this option therefore assumes that the\r
203 server responds appropriately to the command \c{ls\_-la};\r
204 this may not work with all servers.\r
205 \r
206 If SFTP is in use, this option should work with all servers.\r
207 \r
208 \S2{pscp-usage-options-p}\I{-p-PSCP}\c{-p} \i{preserve file attributes}\r
209 \r
210 By default, files copied with PSCP are \i{timestamp}ed with the date and\r
211 time they were copied.  The \c{-p} option preserves the original\r
212 timestamp on copied files.\r
213 \r
214 \S2{pscp-usage-options-q}\I{-q-PSCP}\c{-q} quiet, don't show \i{statistics}\r
215 \r
216 By default, PSCP displays a meter displaying the progress of the\r
217 current transfer:\r
218 \r
219 \c mibs.tar          |   168 kB |  84.0 kB/s | ETA: 00:00:13 |  13%\r
220 \r
221 The fields in this display are (from left to right), filename, size\r
222 (in kilobytes) of file transferred so far, estimate of how fast the\r
223 file is being transferred (in kilobytes per second), estimated time\r
224 that the transfer will be complete, and percentage of the file so far\r
225 transferred.  The \c{-q} option to PSCP suppresses the printing of\r
226 these statistics.\r
227 \r
228 \S2{pscp-usage-options-r}\I{-r-PSCP}\c{-r} copies directories \i{recursive}ly\r
229 \r
230 By default, PSCP will only copy files.  Any directories you specify to\r
231 copy will be skipped, as will their contents.  The \c{-r} option tells\r
232 PSCP to descend into any directories you specify, and to copy them and \r
233 their contents.  This allows you to use PSCP to transfer whole\r
234 directory structures between machines.\r
235 \r
236 \S2{pscp-usage-options-batch}\I{-batch-PSCP}\c{-batch} avoid interactive prompts\r
237 \r
238 If you use the \c{-batch} option, PSCP will never give an\r
239 interactive prompt while establishing the connection. If the\r
240 server's host key is invalid, for example (see \k{gs-hostkey}), then\r
241 the connection will simply be abandoned instead of asking you what\r
242 to do next.\r
243 \r
244 This may help PSCP's behaviour when it is used in automated\r
245 scripts: using \c{-batch}, if something goes wrong at connection\r
246 time, the batch job will fail rather than hang.\r
247 \r
248 \S2{pscp-usage-options-backend}\i\c{-sftp}, \i\c{-scp} force use of\r
249 particular protocol\r
250 \r
251 As mentioned in \k{pscp-usage-basics}, there are two different file\r
252 transfer protocols in use with SSH. Despite its name, PSCP (like many\r
253 other ostensible \cw{scp} clients) can use either of these protocols.\r
254 \r
255 The older \i{SCP protocol} does not have a written specification and\r
256 leaves a lot of detail to the server platform. \ii{Wildcards} are expanded\r
257 on the server. The simple design means that any wildcard specification\r
258 supported by the server platform (such as brace expansion) can be\r
259 used, but also leads to interoperability issues such as with filename\r
260 quoting (for instance, where filenames contain spaces), and also the\r
261 security issue described in \k{pscp-usage-basics}.\r
262 \r
263 The newer \i{SFTP} protocol, which is usually associated with SSH-2\r
264 servers, is specified in a more platform independent way, and leaves\r
265 issues such as wildcard syntax up to the client. (PuTTY's SFTP\r
266 wildcard syntax is described in \k{psftp-wildcards}.) This makes it\r
267 more consistent across platforms, more suitable for scripting and\r
268 automation, and avoids security issues with wildcard matching.\r
269 \r
270 Normally PSCP will attempt to use the SFTP protocol, and only fall\r
271 back to the SCP protocol if SFTP is not available on the server.\r
272 \r
273 The \c{-scp} option forces PSCP to use the SCP protocol or quit.\r
274 \r
275 The \c{-sftp} option forces PSCP to use the SFTP protocol or quit.\r
276 When this option is specified, PSCP looks harder for an SFTP server,\r
277 which may allow use of SFTP with SSH-1 depending on server setup.\r
278 \r
279 \S{pscp-retval} \ii{Return value}\r
280 \r
281 PSCP returns an \i\cw{ERRORLEVEL} of zero (success) only if the files\r
282 were correctly transferred. You can test for this in a \i{batch file},\r
283 using code such as this:\r
284 \r
285 \c pscp file*.* user@hostname:\r
286 \c if errorlevel 1 echo There was an error\r
287 \r
288 \S{pscp-pubkey} Using \i{public key authentication} with PSCP\r
289 \r
290 Like PuTTY, PSCP can authenticate using a public key instead of a\r
291 password. There are three ways you can do this.\r
292 \r
293 Firstly, PSCP can use PuTTY saved sessions in place of hostnames\r
294 (see \k{pscp-usage-basics-host}). So you would do this:\r
295 \r
296 \b Run PuTTY, and create a PuTTY saved session (see\r
297 \k{config-saving}) which specifies your private key file (see\r
298 \k{config-ssh-privkey}). You will probably also want to specify a\r
299 username to log in as (see \k{config-username}).\r
300 \r
301 \b In PSCP, you can now use the name of the session instead of a\r
302 hostname: type \c{pscp sessionname:file localfile}, where\r
303 \c{sessionname} is replaced by the name of your saved session.\r
304 \r
305 Secondly, you can supply the name of a private key file on the command\r
306 line, with the \c{-i} option. See \k{using-cmdline-identity} for more\r
307 information.\r
308 \r
309 Thirdly, PSCP will attempt to authenticate using Pageant if Pageant\r
310 is running (see \k{pageant}). So you would do this:\r
311 \r
312 \b Ensure Pageant is running, and has your private key stored in it.\r
313 \r
314 \b Specify a user and host name to PSCP as normal. PSCP will\r
315 automatically detect Pageant and try to use the keys within it.\r
316 \r
317 For more general information on public-key authentication, see\r
318 \k{pubkey}.\r