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