(PuTTYユーザマニュアルの日本語訳) 6.2 PSFTPを実行する - 6.2 Running PSFTP

http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter6.html#psftp-commandsの日本語訳。<< 6.1 PSFTPを始める - 目次に戻る - 6.3 PSFTPで公開キー認証を使う >>

訳文

PSFTPのセッションを始めると、psftp> プロンプトが現れます。コマンド入力でファイルを転送できます。このセクションでは、利用可能なコマンドを一覧にします。

Once you have started your PSFTP session, you will see a psftp> prompt. You can now type commands to perform file-transfer functions. This section lists all the available commands.

6.2.1 PSFTPコマンドでの一般的なクォート規則 - 6.2.1 General quoting rules for PSFTP commands

PSFTPのコマンドがスペースで区切られている場合には、通常はPSFTPコマンドインタプリタはそのコマンドを複数の単語として扱います。例えば、ren oldfilename newfilenameというコマンドは、三つの単語からなります。ren(コマンド名)、oldfilename(名前を変えるファイルの名前)、そして、newfilename(そのファイルの新しい名前)です。

Most PSFTP commands are considered by the PSFTP command interpreter as a sequence of words, separated by spaces. For example, the command ren oldfilename newfilename splits up into three words: ren (the command name), oldfilename (the name of the file to be renamed), and newfilename (the new name to give the file).

スペースを含むファイル名を指定したい場合は、ファイル名をダブルクォートで囲みます。ダブルクォートは、ローカルのファイル名に対してもリモートのファイル名に対しても同じように動作します。

Sometimes you will need to specify file names that contain spaces. In order to do this, you can surround the file name with double quotes. This works equally well for local file names and remote file names:

psftp> get "spacey file name.txt" "save it under this name.txt"

ここで指定するダブルクォート自体はファイル名の一部にはなりません。ダブルクォートはPSFTPにより削除されます。ダブルクォートの役割は、内部のスペースに単語を区切らせないことだけです。

The double quotes themselves will not appear as part of the file names; they are removed by PSFTP and their only effect is to stop the spaces inside them from acting as word separators.

ダブルクォートを使いたい場合、ダブルクォートを二つ続けて書きます(Unixのように、ファイル名にダブルクォートを含められるリモートシステムもあります)。ダブルクォートの内側と外側のどちらでも、ダブルクォートを二つ続けて書けます。

If you need to use a double quote (on some types of remote system, such as Unix, you are allowed to use double quotes in file names), you can do this by doubling it. This works both inside and outside double quotes. For example, this command

psftp> ren ""this"" "a file with ""quotes"" in it"

これににより、現在(先頭と末尾がダブルクォートの)"this"という名前のファイルは、"quotes" in itという名前に変わります。

will take a file whose current name is "this" (with a double quote character at the beginning and the end) and rename it to a file whose name is a file with "quotes" in it.

PSFTPのクォート規則の唯一の例外は、!コマンドです。!コマンドでは、コマンドラインWindowsにそのまま渡されます。コマンドラインの単語への分割は一切行われません。

(The one exception to the PSFTP quoting rules is the ! command, which passes its command line straight to Windows without splitting it up into words at all. See section 6.2.19.)

6.2.2 PSFTPワイルドカード - 6.2.2 Wildcards in PSFTP

PSFTPには「ワイルドカード」をサポートするコマンドがいくつかあります。ワイルドカードにより複数のファイルを選択できます。

Several commands in PSFTP support ‘wildcards’ to select multiple files.

(putの第一引数などで)ローカルファイルを指定する場合、ローカルのオペレーティングシステムワイルドカード規則が使用されます。例えば、Windowsで実行しているPSFTPで*.*が必要な場面でも、UnixPSFTPであれば*を使用する必要があるでしょう。

For local file specifications (such as the first argument to put), wildcard rules for the local operating system are used. For instance, PSFTP running on Windows might require the use of *.* where PSFTP on Unix would need *.

(getの第一引数などで)リモートファイルを指定する場合、PSFTPは標準的なワイルドカード文法を使います(POSIXワイルドカード似ています)。

For remote file specifications (such as the first argument to get), PSFTP uses a standard wildcard syntax (similar to POSIX wildcards):

  • *は任意の長さの文字列にマッチします(長さ0の文字列も含みます)。

  • ?は単一の文字にマッチします。

  • [abc]はa、bまたはcのいずれか単一の文字にマッチします。

    [a-z]はaからzの範囲の任意の文字にマッチします。

    [^abc]はa、bおよびcのいずれでもない単一の文字にマッチします。

    特殊ケース: [-a]はハイフンかaのいずれかにマッチし、[^-a]はそれ以外の任意の文字にマッチします。[a^]はキャレット(^)かaのいずれかにマッチします。

  • \(バックスラッシュ)を上記の文字(および\)の前に置くと、それらの文字の特殊な意味がなくなります。

  • * matches any sequence of characters (including a zero-length sequence).

  • ? matches exactly one character.

  • [abc] matches exactly one character which can be a, b, or c.

    [a-z] matches any character in the range a to z.

    [^abc] matches a single character that is not a, b, or c.

    Special cases: [-a] matches a literal hyphen (-) or a; [^-a] matches all other characters. [a^] matches a literal caret (^) or a.

  • \ (backslash) before any of the above characters (or itself) removes that character's special meaning.

ファイル名の先頭のピリオド(.)は特殊な扱いをされません。この点はUnixの場合と異なります。そのため、get *は、先頭がピリオドのファイルも含め全てのファイルを取得します。

A leading period (.) on a filename is not treated specially, unlike in some Unix contexts; get * will fetch all files, whether or not they start with a leading period.

6.2.3 openコマンド: セッションを開始する - 6.2.3 The open command: start a session

PSFTPの起動をGUIでのダブルクリックあるいはコマンドラインでのpsftpの入力のみで行った場合、SFTPサーバへの接続を開始するまでコマンドを発行できません(helpとquitは例外です)。

If you started PSFTP by double-clicking in the GUI, or just by typing psftp at the command line, you will need to open a connection to an SFTP server before you can issue any other commands (except help and quit).

接続をするにはopen host.nameと入力します。もし、ユーザ名を指定する必要があれば、open user@host.nameと入力します。

To create a connection, type open host.name, or if you need to specify a user name as well you can type open user@host.name.

いったんopenコマンドを発行すると、(ホスト名の誤入力や接続タイムアウトなどで)失敗してもopenコマンドの再発行はできません。接続が正常に開始できない場合、PSFTPはすぐに終了します。

Once you have issued this command, you will not be able to issue it again, even if the command fails (for example, if you mistype the host name or the connection times out). So if the connection is not opened successfully, PSFTP will terminate immediately.

6.2.4 quitコマンド: セッションを終了する - 6.2.4 The quit command: end your session

セッションを終了するには、quitコマンドを入力します。これにより接続が閉じられ、PSFTPが終了し、コマンドラインに戻ります(PSFTPGUIで起動している場合には、PSFTPコンソールウィンドウが閉じられます)。

When you have finished your session, type the command quit to close the connection, terminate PSFTP and return to the command line (or just close the PSFTP console window if you started it from the GUI).

byeコマンドやexitコマンドもまったく同じように動作します。

You can also use the bye and exit commands, which have exactly the same effect.

6.2.5 closeコマンド: 接続を閉じる - 6.2.5 The close command: close your connection

PSFTPを実行したままネットワーク接続だけを閉じたい場合、closeコマンドを使用します。openコマンドを使えば、新たな接続を開始できます。

If you just want to close the network connection but keep PSFTP running, you can use the close command. You can then use the open command to open a new connection.

6.2.6 helpコマンド: 簡単なオンラインヘルプを見る - 6.2.6 The help command: get quick online help

helpと入力すると、PSFTPは利用可能なコマンドの短い一覧を表示します。

If you type help, PSFTP will give a short list of the available commands.

helpに続けてコマンド名を入力した場合(例えば、help get)、PSFTPは入力したコマンドの短いヘルプを表示します。

If you type help with a command name - for example, help get - then PSFTP will give a short piece of help on that particular command.

6.2.7 cd、および、pwdコマンド: リモートの作業ディレクトリを変更する - 6.2.7 The cd and pwd commands: changing the remote working directory

PSFTPにはサーバ上の「作業ディレクトリ」の概念があります。作業ディレクトリは、他のコマンドが動作するデフォルトのディレクトリになります。例えば、get filename.datと入力すると、PSFTPはリモートサーバ上の作業ディレクトリ内のfilename.datを探します。

PSFTP maintains a notion of your ‘working directory’ on the server. This is the default directory that other commands will operate on. For example, if you type get filename.dat then PSFTP will look for filename.dat in your remote working directory on the server.

リモートの作業ディレクトリを変更するには、cdコマンドを使用します。引数を指定しないでcdを実行すると、サーバ上での作業ディレクトリはホームディレクト(より厳密には、接続の開始時の作業ディレクトリ)に戻ります。

To change your remote working directory, use the cd command. If you don't provide an argument, cd will return you to your home directory on the server (more precisely, the remote directory you were in at the start of the connection).

現在のリモートの作業ディレクトリを表示するには、pwdと入力します。

To display your current remote working directory, type pwd.

6.2.8 lcd、および、lpwdコマンド: ローカルの作業ディレクトリを変更する - 6.2.8 The lcd and lpwd commands: changing the local working directory

PSFTPにはリモートサーバの作業ディレクトリだけでなく、(ほかのWindowsプロセスと同様に)ローカルマシンの作業ディレクトリもあります。これは各コマンドがデフォルトで使うローカルディレクトリです。例えば、get filename.datと入力すると、PSFTPは実行結果のファイルfilename.datをローカルの作業ディレクトリに保存します。

As well as having a working directory on the remote server, PSFTP also has a working directory on your local machine (just like any other Windows process). This is the default local directory that other commands will operate on. For example, if you type get filename.dat then PSFTP will save the resulting file as filename.dat in your local working directory.

ローカルの作業ディレクトリを変更するには、lcdコマンドを使います。現在のローカル作業ディレクトリを表示するには、lpwdと入力します。

To change your local working directory, use the lcd command. To display your current local working directory, type lpwd.

6.2.9 getコマンド: サーバからファイルを取得する - 6.2.9 The get command: fetch a file from the server

ファイルをサーバからダウンロードしてローカルのPCに保存するには、getコマンドを使います。

To download a file from the server and store it on your local PC, you use the get command.

一番簡単な使い方は、ファイル名だけを指定することです。

In its simplest form, you just use this with a file name:

get myfile.dat

ローカルに別名でファイルを保存するには、リモートのファイル名につづけてローカルでのファイル名を指定します。

If you want to store the file locally under a different name, specify the local file name after the remote one:

get myfile.dat newname.dat

これにより、myfile.datファイルをサーバから取得し、newname.datという名前でローカルマシンに保存します。

This will fetch the file on the server called myfile.dat, but will save it to your local machine under the name newname.dat.

ディレクトリ全体を再帰的に取得するには、-rオプションを使います。

To fetch an entire directory recursively, you can use the -r option:

get -r mydir
get -r mydir newname

(ハイフンから始まる名前のファイルを取得するには、--という特殊な引数を使います。この引数から後ろはスイッチとして解釈されなくなります。(例えば、「get -- -silly-name-」。)

(If you want to fetch a file whose name starts with a hyphen, you may have to use the -- special argument, which stops get from interpreting anything as a switch after it. For example, ‘get -- -silly-name-’.)

6.2.10 putコマンド: サーバにファイルを送信する - 6.2.10 The put command: send a file to the server

ファイルをサーバからローカルのPCにアップロードするには、putコマンドを使います。

To upload a file to the server from your local PC, you use the put command.

一番簡単な使い方は、ファイル名だけを指定することです。

In its simplest form, you just use this with a file name:

put myfile.dat

リモートに別名でファイルを保存するには、ローカルのファイル名につづけてリモートのファイル名を指定します。

If you want to store the file remotely under a different name, specify the remote file name after the local one:

put myfile.dat newname.dat

これにより、myfile.datファイルをローカルから送信し、newname.datと言う名前でサーバに保存することができます。

This will send the local file called myfile.dat, but will store it on the server under the name newname.dat.

ディレクトリ全体を再帰的に送信するには、-rオプションを使います。

To send an entire directory recursively, you can use the -r option:

put -r mydir
put -r mydir newname

(ハイフンから始まる名前のファイルを送信するには、--という特殊な引数を使います。この引数から後ろはスイッチとして解釈されなくなります。(例えば、「put -- -silly-name-」。)

(If you want to send a file whose name starts with a hyphen, you may have to use the -- special argument, which stops put from interpreting anything as a switch after it. For example, ‘put -- -silly-name-’.)

6.2.11 mget、および、mputコマンド: 複数のファイルを取得・送信する - 6.2.11 The mget and mput commands: fetch or send multiple files

mgetはgetとほとんど同じように動作しますが、一度に一つ以上のファイルを指定することができます。これには二つの方法があります。

mget works almost exactly like get, except that it allows you to specify more than one file to fetch at once. You can do this in two ways:

  • 二つ以上のファイル名を明示的に指定する(「mget file1.txt file2.txt」)。
  • ワイルドカードを使う(「mget *.txt」)。
  • by giving two or more explicit file names (‘mget file1.txt file2.txt’)
  • by using a wildcard (‘mget *.txt’).

mgetの引数は、取得対象のすべてファイル名(getとは異なります。getでは最低でも引数が一つ必要であり、二つ目の引数は取得したファイルを保存するための別名です。)、もしくは、一つ以上のファイルにマッチさせるためのワイルドカード表現です。

Every argument to mget is treated as the name of a file to fetch (unlike get, which will interpret at most one argument like that, and a second argument will be treated as an alternative name under which to store the retrieved file), or a wildcard expression matching more than one file.

getの-rオプションと--オプションはmgetでも利用できます。

The -r and -- options from get are also available with mget.

mputはputに似ていますが、同様の違いがあります。

mput is similar to put, with the same differences.

6.2.12 - reget、および、reputコマンド: ファイル転送を再開する- 6.2.12 The reget and reput commands: resuming file transfers

ファイル転送が途中で失敗して、ファイルがディスク中に途中まで保存されている場合、regetやreputコマンドを使ってファイル転送を再開できます。これらのコマンドはgetやputコマンドと完全に同じような動作をしますが、書き込み途中の対象ファイルが存在する場合は、最後に中断したところから転送を開始します。

If a file transfer fails half way through, and you end up with half the file stored on your disk, you can resume the file transfer using the reget and reput commands. These work exactly like the get and put commands, but they check for the presence of the half-written destination file and start transferring from where the last attempt left off.

regetとreputの文法はgetやputの文法と完全に同じです。

The syntax of reget and reput is exactly the same as the syntax of get and put:

reget myfile.dat
reget myfile.dat newname.dat
reget -r mydir

通常これらのコマンドは中断された転送の再開のために使用します。リモートのファイルやディレクトリの構造が一切変更されていないことが前提になります。もし変更されている場合、ファイルが破損することがあります。特に、-rオプションを指定した場合、すでに転送が完了したファイルやディレクトリの変更を検知することはありません。

These commands are intended mainly for resuming interrupted transfers. They assume that the remote file or directory structure has not changed in any way; if there have been changes, you may end up with corrupted files. In particular, the -r option will not pick up changes to files or directories already transferred in full.

6.2.13 dirコマンド: リモートのファイルを一覧表示する - 6.2.13 The dir command: list remote files

リモートの作業ディレクトリ内のファイルを一覧表示するには、dirと入力します。

To list the files in your remote working directory, just type dir.

別のディレクトリ内容を一覧表示するには、dirに続けてディレクトリ名を入力します。

You can also list the contents of a different directory by typing dir followed by the directory name:

dir /home/fred
dir sources

さらに、ワイルドカードを指定すれば、ディレクトリの内容の一部を一覧表示することができます。

And you can list a subset of the contents of a directory by providing a wildcard:

dir /home/fred/*.txt
dir sources/*.c

lsコマンドはdirとまったく同じ動作をします。

The ls command works exactly the same way as dir.

6.2.14 chmodコマンド: リモートのファイルの権限を変更する - 6.2.14 The chmod command: change permissions on remote files

PSFTPではサーバ上のファイルやディレクトリの権限を変更することができます。権限の変更するには、chmodコマンドをを使います。chmodはUnixのchmodとほとんど同じように動作します。

PSFTP allows you to modify the file permissions on files and directories on the server. You do this using the chmod command, which works very much like the Unix chmod command.

chmod modes fileが基本的な文法です。modesは変更後のファイルの権限で、fileは権限を変更するファイルの名前です。複数のファイルのしていやワイルドカードの指定も可能です。例えば以下のようになります。

The basic syntax is chmod modes file, where modes represents a modification to the file permissions, and file is the filename to modify. You can specify multiple files or wildcards. For example:

chmod go-rwx,u+w privatefile
chmod a+r public*
chmod 640 groupfile1 groupfile2

modesパラメータにUNIX形式の8進数を指定できます。(UNIX形式の8進数がどういうものか知らなければ、使おうと思わないかもしれません)。別の方法として、modesパラメータに複数の権限変更をカンマで区切って指定することができます。各権限変更は以下を含みます。

The modes parameter can be a set of octal digits in the Unix style. (If you don't know what this means, you probably don't want to be using it!) Alternatively, it can be a list of permission modifications, separated by commas. Each modification consists of:

  • 変更によって影響を受ける人。u(所有ユーザ)、g(所有グループのメンバ)やo(残り全員。「others」)、あるいは、これらの組み合わせです。また、a(「all」)は全員に影響を与えます。
  • +および-記号。権限を追加するか削除するかです。
  • 実際に追加および削除される権限です。r(ファイルの読み取り権限)、w(ファイルの書き込み権限)、そして、x(ファイルの実行権限。あるいは、ディレクトリの場合、ディレクトリ内のファイルにアクセスするための権限)。
  • The people affected by the modification. This can be u (the owning user), g (members of the owning group), or o (everybody else - ‘others’), or some combination of those. It can also be a (‘all’) to affect everybody at once.
  • A + or - sign, indicating whether permissions are to be added or removed.
  • The actual permissions being added or removed. These can be r (permission to read the file), w (permission to write to the file), and x (permission to execute the file, or in the case of a directory, permission to access files within the directory).

したがって、上記の例は以下のような意味になります。

So the above examples would do:

  • 例1: go-rwsは、所有グループのメンバと残り全員から読み取り、書き込みおよび実行権限を削除します。(したがって、ファイルの所有者の権限だけが残ります)。u+wはファイルの所有者に書き込み権限を追加します。
  • 例2: a+rは、「public」で始まるすべてのファイルとディレクトリに読み取り権限を追加します。
  • The first example: go-rwx removes read, write and execute permissions for members of the owning group and everybody else (so the only permissions left are the ones for the file owner). u+w adds write permission for the file owner.
  • The second example: a+r adds read permission for everybody to all files and directories starting with ‘public’.

これらに加えて、Unixシステムにはいくつかの特殊ケースがあります。非Unixシステムではこれらはあまり役に立ちません。

In addition to all this, there are a few extra special cases for Unix systems. On non-Unix systems these are unlikely to be useful:

  • u+sやu-sを指定すると、Unixのsetuidビットの追加や削除を行えます。通常、これは特別な用途でしか使いません。よくわからない場合、Unixのドキュメントを参照してください。
  • g+sやg-sを指定すると、Unixのsetgidビットの追加や削除を行えます。ファイルの場合、setuidビット同じように動作します(これについてもUnixのドキュメントを参照してください)。ディレクトリの場合、ディレクトリの所有グループのメンバだけが、ディレクトリ内に作成されたファイルにアクセスできるようになります。
  • +tや-tを指定すると、Unixの「スティッキービット」の追加や削除を行えます。ディレクトリに適用すると、ディレクトリ内のファイルの削除をファイルの所有者が行えるようになります(通常の場合、ディレクトリの所有者以外はディレクトリ内のファイルを削除できません)。
  • You can specify u+s and u-s to add or remove the Unix set-user-ID bit. This is typically only useful for special purposes; refer to your Unix documentation if you're not sure about it.
  • You can specify g+s and g-s to add or remove the Unix set-group-ID bit. On a file, this works similarly to the set-user-ID bit (see your Unix documentation again); on a directory it ensures that files created in the directory are accessible by members of the group that owns the directory.
  • You can specify +t and -t to add or remove the Unix ‘sticky bit’. When applied to a directory, this means that the owner of a file in that directory can delete the file (whereas normally only the owner of the directory would be allowed to).
6.2.15 delコマンド: リモートのファイルを削除する - 6.2.15 The del command: delete remote files

サーバ上のディレクトリを削除するには、delにつづけて一つ以上のファイル名を入力します。

To delete a file on the server, type del and then the filename or filenames:

del oldfile.dat
del file1.txt file2.txt
del *.o

複数のファイルを指定した場合でも、確認なしにファイルは削除されます。

Files will be deleted without further prompting, even if multiple files are specified.

delはファイルだけを削除します。ディレクトリは削除できません。ディレクトリの削除のためにはrmdirを使ってください。

del will only delete files. You cannot use it to delete directories; use rmdir for that.

rmコマンドもdelと完全に同じ動作をします。

The rm command works exactly the same way as del.

6.2.16 mkdirコマンド: リモートにディレクトリを作成する - 6.2.16 The mkdir command: create remote directories

サーバ上にディレクトリを作成するには、mkdirにつづけてディレクトリ名を入力します。

To create a directory on the server, type mkdir and then the directory name:

mkdir newstuff

複数のディレクトリを指定すれば、一度に複数のディレクトリを作成できます。

You can specify multiple directories to create at once:

mkdir dir1 dir2 dir3
6.2.17 rmdirコマンド: リモートのディレクトリを削除する - 6.2.17 The rmdir command: remove remote directories

サーバ上のディレクトリを削除するには、rmdirに続けて一つ以上のディレクトリ名を入力します。

To remove a directory on the server, type rmdir and then the directory name or names:

rmdir oldstuff
rmdir *.old ancient

複数のディレクトリを指定しても、確認なしにディレクトリは削除されます。

Directories will be deleted without further prompting, even if multiple directories are specified.

ほとんどのSFTPサーバは、中身のあるディレクトリの削除を許可しません。その場合、中身を先に削除する必要があります。

Most SFTP servers will probably refuse to remove a directory if the directory has anything in it, so you will need to delete the contents first.
6.2.18 mvコマンド: リモートのファイルの移動と名前の変更を行う - 6.2.18 The mv command: move and rename remote files

サーバ上の単一のファイルの名前を変更するには、mvに続けて現在のファイル名と新しいファイル名を入力します:

To rename a single file on the server, type mv, then the current file name, and then the new file name:

mv oldfile newname

また、ファイルを別のディレクトリに移動することや名前を変更することもできます。

You can also move the file into a different directory and change the name:

mv oldfile dir/newname

一つ以上のファイルを既存のサブディレクトリに移動するには、(必要であればワイルドカードを使って)複数のファイルを指定し、続けて移動先のディレクトリを指定します。

To move one or more files into an existing subdirectory, specify the files (using wildcards if desired), and then the destination directory:

mv file dir
mv file1 dir1/file2 dir2
mv *.c *.h ..

renameとrenコマンドはmvと完全に同じ動作をします。

The rename and ren commands work exactly the same way as mv.

6.2.19 !コマンド: ローカルのWindowsコマンドを実行する - 6.2.19 The ! command: run a local Windows command

!コマンドを使うと、ローカルのWindowsコマンドを実行できます。これはPSFTPコマンドの中でも、6.2.1.節で説明したクォート規則の唯一の対象外です。!文字で始まるコマンドは、!より後ろの部分が一切変換されずそのままWindowsに渡されます。

You can run local Windows commands using the ! command. This is the only PSFTP command that is not subject to the command quoting rules given in section 6.2.1. If any command line begins with the ! character, then the rest of the line will be passed straight to Windows without further translation.

例えば、更新されたバージョンのダウンロード前に、既存のファイルをコピーしたい場合、以下のように入力すると、

For example, if you want to move an existing copy of a file out of the way before downloading an updated version, you might type:

psftp> !ren myfile.dat myfile.bak
psftp> get myfile.dat

Windowsのrenコマンドを使ってローカルPCのファイルの名前を変更します。

using the Windows ren command to rename files on your local PC.

<< 6.1 PSFTPを始める - 目次に戻る - 6.3 PSFTPで公開キー認証を使う >>