(PuTTYユーザマニュアルの日本語訳) 5.2 PSCPの使い方 - 5.2 PSCP Usage

http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html#pscp-usageの日本語訳<< 5.1 PSCPを始める - 目次に戻る - 6章: PSFTPを使ってファイルを安全に転送する >>

訳文

入力するためのコンソールウィンドウの起動後、pscpとだけ入力すれば使い方のメッセージが表示されます。これを見ると、使用しているPSCPのバージョンとPSCPの使い方の概要がわかります。

Once you've got a console window to type into, you can just type pscp on its own to bring up a usage message. This tells you the version of PSCP you're using, and gives you a brief summary of how to use PSCP:

Z:\owendadmin>pscp
PuTTY Secure Copy client
Release 0.60
Usage: pscp [options] [user@]host:source target
       pscp [options] source [source...] [user@]host:target
       pscp [options] -ls [user@]host:filespec
Options:
  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -p        preserve file attributes
  -q        quiet, don't show statistics
  -r        copy directories recursively
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -P port   connect to specified port
  -l user   connect with specified username
  -pw passw login with specified password
  -1 -2     force use of particular SSH protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -batch    disable all interactive prompts
  -unsafe   allow server-side wildcards (DANGEROUS)
  -sftp     force use of SFTP protocol
  -scp      force use of SCP protocol
(PSCP's interface is much like the Unix scp command, if you're familiar with that.)

5.2.1 基本 - 5.2.1 The basics

リモートサーバからファイルを受け取るには:

To receive (a) file(s) from a remote server:

pscp [options] [user@]host:source target

ファイル/etc/hostsをexample.comサーバからユーザfredとしてc:\temp\example-hosts.txtへコピーするには、以下を入力します:

So to copy the file /etc/hosts from the server example.com as user fred to the file c:\temp\example-hosts.txt, you would type:

pscp fred@example.com:/etc/hosts c:\temp\example-hosts.txt

ファイルをリモートサーバに送るには:

To send (a) file(s) to a remote server:

pscp [options] source [source...] [user@]host:target

ローカルファイルc:\documents\foo.txtをexample.comサーバのユーザfredとして/tmp/fooに送るには、以下を入力します:

So to copy the local file c:\documents\foo.txt to the server example.com as user fred to the file /tmp/foo you would type:

pscp c:\documents\foo.txt fred@example.com:/tmp/foo

複数のファイルの各方向への転送でワイルドカードを使うには、このようにします:

You can use wildcards to transfer multiple files in either direction, like this:

pscp c:\documents\*.doc fred@example.com:docfiles
pscp fred@example.com:source/*.c c:\source

しかし、(複数のリモートファイルにワイルドカードを使っている)二つ目の例では「警告: 「*.c」というファイルを要求に対し、リモートホストは「terminal.c」というファイルに書き込もうとしました。これがワイルドカードの場合、SSH-2にアップグレードするか、「-unsafe」オプションを使ってください。このファイルの名前の変更は許可されていません」のような警告があるかもしれません。

However, in the second case (using a wildcard for multiple remote files) you may see a warning saying something like ‘warning: remote host tried to write to a file called ‘terminal.c’ when we requested a file called ‘*.c’. If this is a wildcard, consider upgrading to SSH-2 or using the ‘-unsafe’ option. Renaming of this file has been disallowed’.

これは、古い形式のSCPプロトコルが基本的に安全でないためです。クライアントがワイルドカード文字列(*.c)をサーバに送信すると、サーバはワイルドカードパターンにマッチするファイル名のシーケンスを送り返します。しかし、サーバに違うパターンを送り返されると他のファイルを上書きされてしまいます。*.cを要求しても、サーバによりAUTOEXCE.BATを返されれば、ウイルスをインストールしてしまうかもしれません。サーバがワイルドカードマッチングのルールを決めるため、クライアントは送り返されるファイル名がパターンにマッチしているかを確実に検証することができないのです。

This is due to a fundamental insecurity in the old-style SCP protocol: the client sends the wildcard string (*.c) to the server, and the server sends back a sequence of file names that match the wildcard pattern. However, there is nothing to stop the server sending back a different pattern and writing over one of your other files: if you request *.c, the server might send back the file name AUTOEXEC.BAT and install a virus for you. Since the wildcard matching rules are decided by the server, the client cannot reliably verify that the filenames sent back match the pattern.

PSCPは可能であれば、このセキュリティ上の欠陥をもたない、最新のSFTPプロトコル(SSH-2の一部)を使おうとします。SFTPをサポートするSSH-2サーバと通信しているなら、この警告をみることはないでしょう。(-sftpを指定すると、利用可能であれば、SFTPプロトコルの使用を強制できます - 5.2.2.6節を参照)

PSCP will attempt to use the newer SFTP protocol (part of SSH-2) where possible, which does not suffer from this security flaw. If you are talking to an SSH-2 server which supports SFTP, you will never see this warning. (You can force use of the SFTP protocol, if available, with -sftp - see section 5.2.2.6.)

SSH-1サーバでサーバサイドのワイルドカードをどうしても使わなければならない場合、PSCPに-unsafeコマンドラインオプションを付ければ使えます。

If you really need to use a server-side wildcard with an SSH-1 server, you can use the -unsafe command line option with PSCP:

pscp -unsafe fred@example.com:source/*.c c:\source

これにより警告メッセージが抑制され、ファイルが転送されます。しかし、このオプションを使うことは、対象ディレクトリのすべてのファイルへの書き込みをサーバに許可することに注意すべきです。サーバの管理者に悪意がない(かつ、悪意のある者にマシンがクラックされていない)ことを信頼できる場合にこのオプションを使うべきです。あるいは、新たに作った空のディレクトリの中にダウンロードしてください。(「unsafe」モードでも、PSCPはサーバが「..」を含むパス名を使ってディレクトリの外にでようとすることからは抑制します。)

This will suppress the warning message and the file transfer will happen. However, you should be aware that by using this option you are giving the server the ability to write to any file in the target directory, so you should only use this option if you trust the server administrator not to be malicious (and not to let the server machine be cracked by malicious people). Alternatively, do any such download in a newly created empty directory. (Even in ‘unsafe’ mode, PSCP will still protect you against the server trying to get out of that directory using pathnames including ‘..’.)

5.2.1.1 ユーザ - 5.2.1.1 user

リモートサーバのログイン名。これを省略しており、かつホストがPuTTY保存セッションの場合、PSCPは保存セッションで指定されているユーザ名を使います。さもなくば、ローカルのWindowsのユーザ名を使おうとします。

The login name on the remote server. If this is omitted, and host is a PuTTY saved session, PSCP will use any username specified by that saved session. Otherwise, PSCP will attempt to use the local Windows username.

5.2.1.2 ホスト - 5.2.1.2 host

リモートサーバの名前、または既存のPuTTY保存セッション。後の例では、セッションの設定のホスト名、ポート番号、暗号種別やユーザ名を使います。

The name of the remote server, or the name of an existing PuTTY saved session. In the latter case, the session's settings for hostname, port number, cipher type and username will be used.

5.2.1.3 コピー元 - 5.2.1.3 source

コピー元となる一つまたは複数のファイル。ワイルドカードも可能。ワイルドカードの文法は適用されるシステムに依存し、もしWindowsシステムからUNIXシステムにコピーするなら、Windowsワイルドカード文法 (例えば、*.*)を使うべきですが、UNIXシステムからWindowsシステムにコピーするならUNIXシェルの許可する文法(例えば、*)を使います。

One or more source files. Wildcards are allowed. The syntax of wildcards depends on the system to which they apply, so if you are copying from a Windows system to a UNIX system, you should use Windows wildcard syntax (e.g. *.*), but if you are copying from a UNIX system to a Windows system, you would use the wildcard syntax allowed by your UNIX shell (e.g. *).

リモートサーバのがコピー元で、フルパス名(UNIXでは、/(スラッシュ)文字から始まるパス名)を指定しない場合、コピー元の指定はリモートサーバのホームディレクトリからの相対パスとして解釈されます。

If the source is a remote server and you do not specify a full pathname (in UNIX, a pathname beginning with a / (slash) character), what you specify as a source will be interpreted relative to your home directory on the remote server.

5.2.1.4 コピー先 - 5.2.1.4 target

ファイルを置くためのファイル名またはディレクトリ。リモートサーバからローカルホストにコピーする場合、ファイルを単に現在のディレクトリに置きたいこともあるでしょう。このような場合、.をコピー先として指定します。たとえば:

The filename or directory to put the file(s). When copying from a remote server to a local host, you may wish simply to place the file(s) in the current directory. To do this, you should specify a target of .. For example:

pscp fred@example.com:/home/tom/.emacs .

・・・リモートサーバの/home/tom/.emacsが現在のディレクトリにコピーされます。

...would copy /home/tom/.emacs on the remote server to the current directory.

コピー元パラメータの指定のように、コピー先がリモートサーバで、フルパス名でない場合、リモートサーバのホームディレクトリから相対パスとして解釈されます。

As with the source parameter, if the target is on a remote server and is not a full path name, it is interpreted relative to your home directory on the remote server.

5.2.2 オプション - 5.2.2 Options

PSCPPuTTYツールがサポートする一般的なコマンドラインオプションを、ファイル転送ユーティリティでは無意味なものを除いて、すべてサポートします。これらのオプションの詳細は3.8.3節を参照してください。(PCSPがサポートしないものは明らかです。)

PSCP accepts all the general command line options supported by the PuTTY tools, except the ones which make no sense in a file transfer utility. See section 3.8.3 for a description of these options. (The ones not supported by PSCP are clearly marked.)

PCSPは独自のオプションもいくつかさぽーとします。以下の節はPSCP特有のコマンドラインオプションを説明します。

PSCP also supports some of its own options. The following sections describe PSCP's specific command-line options.

5.2.2.1 -ls リモートのファイルを一覧表示する - 5.2.2.1 -ls list remote files

-lsオプションを指定しても、ファイルは転送されません。代わりに、リモートファイルが一覧表示されます。ホスト名の指定とオプションでのリモートファイルの指定だけを行います。たとえば:

If the -ls option is given, no files are transferred; instead, remote files are listed. Only a hostname specification and optional remote file specification need be given. For example:

pscp -ls fred@example.com:dir1

SCPプロトコルにはファイルを一覧表示する方法はありません。SCPを使う場合、このオプションはサーバがコマンドls -laに適切に応答することを想定します。すべてのサーバで動作するとはかぎりません。

The SCP protocol does not contain within itself a means of listing files. If SCP is in use, this option therefore assumes that the server responds appropriately to the command ls -la; this may not work with all servers.

SFTPを使っている場合、このオプションはすべてのサーバで動作します。

If SFTP is in use, this option should work with all servers.

5.2.2.2 -p ファイルの属性を保持する - 5.2.2.2 -p preserve file attributes

デフォルトでは、PSCPでコピーされたファイルのタイムスタンプはコピーされた日時になります。-pオプションはオリジナルのタイムスタンプを保持します。

By default, files copied with PSCP are timestamped with the date and time they were copied. The -p option preserves the original timestamp on copied files.

5.2.2.3 -q 静かに、統計を表示しない 5.2.2.3 -q quiet, don't show statistics

デフォルトでは、PSCPは現在の転送の進捗がわかるメーターを表示します。

By default, PSCP displays a meter displaying the progress of the current transfer:

mibs.tar          |   168 kB |  84.0 kB/s | ETA: 00:00:13 |  13%

表示項目は(左から順に)、ファイル名、これまでに転送されたファイルのサイズ(キロバイト単位)、ファイルの推定転送速度、推定転送完了時間、そして、これまでに送信されたファイルの割合です。PSCPの-qオプションはこれらの統計の表示を抑制します。

The fields in this display are (from left to right), filename, size (in kilobytes) of file transferred so far, estimate of how fast the file is being transferred (in kilobytes per second), estimated time that the transfer will be complete, and percentage of the file so far transferred. The -q option to PSCP suppresses the printing of these statistics.

5.2.2.4 -r ディレクトリを再帰的にコピーする - 5.2.2.4 -r copies directories recursively

デフォルトでは、PSCPはファイルだけをコピーします。ディレクトリのコピーを指定しても、ディレクトリもその中身もコピーされません。-rオプションを指定すると、PSCPは指定したディレクトリを下っていき、ディレクトリとその中身をコピーします。これにより、PSCPを使ってすべてのディレクトリ構造をマシン間で転送できます。

By default, PSCP will only copy files. Any directories you specify to copy will be skipped, as will their contents. The -r option tells PSCP to descend into any directories you specify, and to copy them and their contents. This allows you to use PSCP to transfer whole directory structures between machines.

5.2.2.5 -batch 対話用のプロンプトを無効にする - 5.2.2.5 -batch avoid interactive prompts

-batchオプションを使うと、PSCPは接続の確立のために対話用のプロンプトを表示しません。例えば(2.2節参照)、サーバのホストキーが不正な場合、次にどうするのかを尋ねることもなく接続は単純に中止されます。

If you use the -batch option, PSCP will never give an interactive prompt while establishing the connection. If the server's host key is invalid, for example (see section 2.2), then the connection will simply be abandoned instead of asking you what to do next.

これは自動化されたスクリプトを使う場合にPCSPのふるまいを補助します。-batchを使うと、接続時間が不正な場合でも、バッチジョブはハングアップすることなく失敗します。

This may help PSCP's behaviour when it is used in automated scripts: using -batch, if something goes wrong at connection time, the batch job will fail rather than hang.

5.2.2.6 -sftp, -scp 強制的に特定のプロトコルを使わせる - 5.2.2.6 -sftp, -scp force use of particular protocol

5.2.1節で述べたとおり、SSHでは二つの別のファイル転送プロトコルを使えます。名前にもかかわらず、(他の多くの目立つscpクライアントと同様)PSCPではこれらのプロトコルをどちらも使えます。

As mentioned in section 5.2.1, there are two different file transfer protocols in use with SSH. Despite its name, PSCP (like many other ostensible scp clients) can use either of these protocols.

古いSCPプロトコルは文書による仕様がなく、詳細はサーバプラットホームに任されています。ワイルドカードはサーバで拡張されます。この単純な設計により、サーバプラットフォームがサポートするどんなワイルドカード仕様でも使うことができますが、ファイル名の(例えば、ファイル名がスペースを含む場合の)クオートに互換性がない問題や、5.2.1節で述べたセキュリティ問題が起こっています。

The older SCP protocol does not have a written specification and leaves a lot of detail to the server platform. Wildcards are expanded on the server. The simple design means that any wildcard specification supported by the server platform (such as brace expansion) can be used, but also leads to interoperability issues such as with filename quoting (for instance, where filenames contain spaces), and also the security issue described in section 5.2.1.

最新の、たいていSSH-2サーバを連想させる、SFTPプロトコルでは、多くのプラットフォームから独立したやり方で、ワイルドカード文法のような問題をクライアントに任せています。(PuTTYのSFTPワイルドカード文法は6.2.2節で述べています。)これは、プラットフォーム間で一貫性が増し、スクリプトの記述や自動化により適切になり、ワイルドカードマッチングによるセキュリティ問題を避けることができます。

The newer SFTP protocol, which is usually associated with SSH-2 servers, is specified in a more platform independent way, and leaves issues such as wildcard syntax up to the client. (PuTTY's SFTP wildcard syntax is described in section 6.2.2.) This makes it more consistent across platforms, more suitable for scripting and automation, and avoids security issues with wildcard matching.

通常PSCPはSFTPをプロトコルを使おうとしますが、サーバでSFTPが使用可能でない場合、SCPプロトコルを使います。

Normally PSCP will attempt to use the SFTP protocol, and only fall back to the SCP protocol if SFTP is not available on the server.

-scpオプションは、PSCPがSCPプロトコルを使うか、さもなくば終了することを、強制します。

The -scp option forces PSCP to use the SCP protocol or quit.

-sftpオプションは、PSCPがSFTPプロトコルを使うか、さもなくば終了することを、強制します。このオプションを指定すると、PSCPは、SFTPサーバがサーバの設定に依存するSSH-1によるSFTPの使用を許可しているかをよく調べます。

The -sftp option forces PSCP to use the SFTP protocol or quit. When this option is specified, PSCP looks harder for an SFTP server, which may allow use of SFTP with SSH-1 depending on server setup.

5.2.3 戻り値 - 5.2.3 Return value

ファイルが正しく転送された場合のみ、PSCPは0(成功)のERRORLEVELを返します。バッチファイルでこのテストをするには、以下のようなコードを使います:

PSCP returns an ERRORLEVEL of zero (success) only if the files were correctly transferred. You can test for this in a batch file, using code such as this:

pscp file*.* user@hostname:
if errorlevel 1 echo There was an error

5.2.4 PCSPで公開キー認証を使う - 5.2.4 Using public key authentication with PSCP

PuTTYのように、PSCPはパスワードの代わりに公開キーを使った認証を使用できます。このためには三つの方法があります。

Like PuTTY, PSCP can authenticate using a public key instead of a password. There are three ways you can do this.

第一は、PSCPでホスト名の代わりにPuTTY保存セッションを使うことができます(5.2.1.2節参照)。このようにします:

Firstly, PSCP can use PuTTY saved sessions in place of hostnames (see section 5.2.1.2). So you would do this:

  • PuTTYを起動し、秘密キーファイル(4.20.7節参照)を指定してPuTTY保存セッション(4.1.2節参照)を作ります。ログインするためのユーザ名(4.14.1参照)を指定したいこともあるでしょう。
  • PSCPで、ホスト名のかわりにセッションの名前を使います。sessionnameを保存セッションの名前に置き換えて、pscp sessionname:file localfileを入力します。
  • Run PuTTY, and create a PuTTY saved session (see section 4.1.2) which specifies your private key file (see section 4.20.7). You will probably also want to specify a username to log in as (see section 4.14.1).
  • In PSCP, you can now use the name of the session instead of a hostname: type pscp sessionname:file localfile, where sessionname is replaced by the name of your saved session.

第二は、-lオプションを使って、秘密キーファイルをコマンドラインで指定します。詳細な情報は3.8.3.18節を参照してください。

Secondly, you can supply the name of a private key file on the command line, with the -i option. See section 3.8.3.18 for more information.

第三は、Pageant(9章参照)起動している場合、PSCPPageantを使って認証しようとします。このようにします:

Thirdly, PSCP will attempt to authenticate using Pageant if Pageant is running (see chapter 9). So you would do this:

  • Pageantが起動していることと、秘密キーが保存されていることを確認します。
  • 通常通りPSCPでユーザとホスト名を指定します。PCSPは自動的にPageantを見つけ、Pageant内のキーを使おうとします。
  • Ensure Pageant is running, and has your private key stored in it.
  • Specify a user and host name to PSCP as normal. PSCP will automatically detect Pageant and try to use the keys within it.

公開キー認証についてのより一般的な情報は、8章を参照してください。

For more general information on public-key authentication, see chapter 8.

<< 5.1 PSCPを始める - 目次に戻る - 6章: PSFTPを使ってファイルを安全に転送する >>