pscp.but 14 KB

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