pscp.but 13 KB

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