pscp.but 14 KB

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