pscp.but 14 KB

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