ネットワークで接続されているマシン間でファイルを転送するには、ftp コマンド(機能)を使用します。
プロンプト(入力促進記号):キーボード からの入力を待っている時に表示される 文字列(記号) |
ftp はコマンドプロンプトのウィンドウ上で実行しますので、まずコマンドプロンプトを起動します。
「コマンドプロンプト」を起動するには、「スタート」→「プログラム」→「コマンドプロンプト」と選択します。コマンドプロンプトは MS-DOS のコマンドを実行するためのウィンドウです。
コマンドプロンプトのウィンドウが開かれると、プロンプト c:\> が表示されています。
ftpでリモートマシンに接続するには、コマンドプロンプトでプロンプト c:\> が表示されているところで、次のように ftp www.k.hosei.ac.jp と入力します。ここでは、マシンからのメッセージと入力部分を区別するため、入力した文字列には下線をつけています。www.k.hosei.ac.jp は接続するリモートマシンのホスト名です。接続されると User を聞いてきます。ホスト名の入力を間違えたときは、エラーメッセージが表示され、プロンプトが ftp> になりますので、open www.k.hosei.ac.jp と入力しなおします。
Microsoft(R) Windows NT(R) (C) Copyright 1985-1996 Microsoft Corp. c:\>ftp www.k.hosei.ac.jp Connected to www.k.hosei.ac.jp. 220 www FTP server (UNIX(r) System V Release 4.0) ready. User (www.k.hosei.ac.jp:(none)): g9xxxxxx 331 Password required for g9xxxxxx. PassworSd: 230 User g9xxxxxx logged in. ftp> |
User(… ): のところでID番号を入力し、Password: でパスワードを入力します。入力したパスワードは表示されません。ログインできると、230 User g9xxxxxx logged in. と表示されプロンプトが ftp> となります。
・ftpで使用できるコマンドプロンプト ftp> が表示されているところで ? を入力すると、ftp で使用できるコマンドの一覧が表示されます。UNIX のコマンドと全く同じものもありますが、ファイルを転送するための特別なものもあります。コマンドを忘れたときにはこれを表示して見てください。
ftp> ? Commands may be abbreviated. Commands are: ! delete literal prompt send ? debug ls put status append dir mdelete pwd trace ascii disconnect mdir quit type bell S get mget quote user binary glob mkdir recv verbose bye hash mls remotehelp cd help mput rename close lcd open rmdir ftp> |
ftp でリモートマシンにログインするとカレントディレクトリはホームディレクトリになっています。
ftp> pwd 257 "/home/eng1/arc/g9xxxxxx" is current directory. ftp> |
pwd コマンドでカレントディレクトリを表示します。
ftp> mkdir public_html 257 MKD command successful. ftp> |
カレントディレクトリの下にディレクトリ public_html を作成します。
ftp> rmdir public_html 250 RMD command successful. ftp> |
ディレクトリ public_html を削除します。ディレクトリの下にファイルやディレクトリがあると削除できません。
ftp> cd public_html 250 CWD command successful. ftp> |
カレントディレクトリを public_html に移動します。
ftp> cd .. 250 CWD command successful. ftp> |
カレントディレクトリを親(1つ上のレベル)ディレクトリに移動します。
ftp> lcd Local directory now c:\ ftp> lcd d:\ Local directory now D:\ ftp> lcd public_html Local directory now D:\public_html ftp> |
ローカルマシンのディレクトリ d:\ に移動し、次にを public_html に移動します。
ftp> lcd .. 250 CWD command successful. ftp> |
ローカルマシンのカレントディレクトリを親(1つ上のレベル)ディレクトリに移動します。
リモートマシンのディレクトリのディレクトリリスト(ファイル一覧)を表示するコマンドは ls です。この例では、カレントディレクトリ public_html にファイル index.html とディレクトリ csrc と imagefile があることが分ります。
ftp> ls 200 PORT command successful. 150 ASCII data connection for /bin/ls (133.25.210.133,1033) (0 bytes). csrc imagefile index.html 226 ASCII Transfer complete. 36 bytes received in 0.08 seconds (0.45 Kbytes/sec) ftp> |
l オプションをつけるとファイルやディレクトリの属性、所有者、グループなどが表示されます。
ftp> ls -l 200 PORT command successful. 150 ASCII data connection for /bin/ls (133.25.210.133,1041) (0 bytes). total 10 drwxr-xr-x 2 g9xxxxxx student 512 Sep 21 15:54 csrc drwxr-xr-x 4 g9xxxxxx student 512 Nov 19 15:18 enshu drwxr-xr-x 2 g9xxxxxx student 512 Sep 21 15:55 imagefile -rw-r--r-- 1 g9xxxxxx student 1242 Oct 19 16:52 index.html 226 ASCII Transfer complete. 262 bytes received in 0.03 seconds (8.73 Kbytes/sec) ftp> |
a オプションをつけるとファイル名の先頭が . のファイル(隠しファイル)も表示されます。 . は自分自身、.. は親ディレクトリ(1つ上のレベルのディレクトリ)を指します。
ftp> ls -al 200 PORT command successful. 150 ASCII data connection for /bin/ls (133.25.210.133,1044) (0 bytes). total 14 drwxr-xr-x 5 g9xxxxxx student 512 Nov 21 13:00 . drwxr-xr-x 4 g9xxxxxx student 512 Nov 21 13:02 .. drwxr-xr-x 2 g9xxxxxx student 512 Sep 21 15:54 csrc drwxr-xr-x 4 g9xxxxxx student 512 Nov 19 15:18 enshu drwxr-xr-x 2 g9xxxxxx student 512 Sep 21 15:55 imagefile -rw-r--r-- 1 g9xxxxxx student 1242 Oct 19 16:52 index.html 226 ASCII Transfer complete. 377 bytes received in 0.02 seconds (18.85 Kbytes/sec) ftp> |
ローカルマシンのカレントディレクトリのディレクトリリスト(ファイル一覧)を表示するコマンドは !dir です。この例では、カレントディレクトリ public_html にディレクトリ csrc とimagefile があることが分ります。
ftp> !dir ドライブ D のボリューム ラベルはありません。 ボリューム シリアル番号は 3732-0B09 です D:\public_html のディレクトリ 98/09/21 03:28p <DIR> . 98/09/21 03:28p <DIR> .. 98/04/20 02:50p 1,242 index.html 98/09/21 03:29p <DIR> csrc 98/09/21 03:31p <DIR> imagefile 5 個のファイル 1,242 バイト 17,913,856 バイトの空き領域 ftp> |
ローカルマシンからリモートマシンへファイルを転送するコマンドは put です。反対にリモートマシンからローカルマシンへ転送する場合は get です。ファイルがバイナリ(テキスト(文字情報のみ)のみではない)データの時は転送する前に binary(bin) コマンドを実行しておきます。ファイルがテキストのみかどうか分らない時は、binary コマンドを実行しておくと安全です。
ftp> binary 200 Type set to I. ftp> put index.html 200 PORT command successful. 150 Binary data connection for index.html (133.25.200.167,1034). 226 Transfer complete. 1242 bytes sent in 0.00 seconds (1242000.00 Kbytes/sec) ftp> |
ここではbinaryコマンドを実行してから、ファイル index.html をローカルマシンからリモートマシンへ転送しています。
・ファイル名の変更
ftp> rename tiger.html dog.html 350 File exists, ready for destination name 250 RNTO command successful. ftp> |
ファイル名 tiger.html を dog.html に変更します。
ftp> delete cat.html 250 DELE command successful. ftp> |
ファイル cat.html を 削除します。
ftp> bye 221 Goodbye c:\> |
ftp を終了するコマンドは bye(by) です。コマンドプロンプトのプロンプト c:\> に戻ります。