Section Next | Prev


4.2 ファイル転送(ftp)

【機能説明】
ローカルホストとリモートホストとの間でファイル転送を行なう為の ユーティリティです。 ホストを指定した場合には、自動的にリモートホストとのコネクションを作成 してから、コマンド入力待ちになります。

【入力フォーマット】
ftp [ホスト名]

【主なサブコマンド】
ftp を起動するとプロンプトが表示され、コマンド待ちになります。 コマンドを入力する時に必要な引き数が欠落している場合は、 その引き数名を表示し入力待ちになります。 ftp の主なコマンドは以下の通り。

open HOST
指定されたホスト (HOST) のFTPサーバと接続します。 オートログイン・オプション(-n)が指定されている時には、 自動的に接続手続きを開始します。 この時のユーザ名はクライアントにログインしているものが採用されます。
	$ ftp osku01
	Connected to osku01.osa.dec.com.
	220 osku01.osa.dec.com FTP server (OSF/1 Version 5.60) ready.
	Name (osku01:yakoshi):
	331 Password required for yakoshi.
	Password: ********
	230 User yakoshi logged in.
	Remote system type is UNIX.
	Using binary mode to transfer files.
	ftp> quit
	221 Goodbye.

	$ ftp -n osku01
	Connected to osku01.osa.dec.com.
	220 osku01.osa.dec.com FTP server (OSF/1 Version 5.60) ready.
	ftp> user
	(username) yakoshi
	331 Password required for yakoshi.
	Password: ********
	230 User yakoshi logged in.
	ftp> quit
	221 Goodbye.
user USER
リモートホストの指定したユーザ (USER) で、FTPサーバに ログインします。
このときサーバの /etc/ftpusers に登録されているユーザではログイン できません。
公開FTPサーバの場合、ユーザ名は anonymous または ftp を使い、 パスワードには連絡先(メールアドレス)を入力します。
	$ ftp osaka
	Connected to osaka.
	220 osaka FTP server (OSF/1 Version 5.60) ready.
	Name (osaka:yakoshi): root
	530 User root access denied.
	Login failed.
	Remote system type is UNIX.
	Using binary mode to transfer files.
	ftp> user
	(username) root
	530 User root access denied.
	Login failed.
	ftp> quit
	221 Goodbye.

close
リモートサーバとのコネクションを解放して、コマンドモードに戻ります。

quit
リモートサーバとのコネクションを解放して、 ftp を終了します。
同様のコマンドに bye があります。

ascii
ファイル転送タイプをアスキー転送に設定します。
UNIX 同士の場合は意味はありません。

binary
ファイル転送タイプをバイナリ・イメージ転送に設定します。
UNIX 同士の場合には意味がありません。

status
ftp の現在の状況を表示します。
	ftp> status
	Connected to osaka.
	No proxy connection.
	Mode: stream; Type: binary; Form: non-print; Structure: file
	Verbose: on; Bell: off; Prompting: on; Globbing: on
	Store unique: off; Receive unique: off
	Case: off; CR stripping: on
	Ntrans: off
	Nmap: off
	Hash mark printing: off; Use of PORT cmds: on
! [コマンド]
ローカルマシン上のシェルを起動します。

get リモートファイル名 [ローカルファイル]
リモートファイルをローカルファイルにコピーします。 ローカルファイル名を指しなければ、同じ名前でコピーされます。

put ローカルファイル名 [リモートファイル]
ローカルファイルをリモートファイルにコピーします。 リモートファイル名を指定しなければ、同じ名前でコピーされます。

rename FROM TO
リモートマシン上のファイルの名前を FROM から TO に変えます。

delete ファイル名
リモートマシン上のファイルを削除します。

mget リモートファイル名...
リモートマシン上の複数ファイルをローカルマシン上のカレントディレクトリに コピーします。ファイル指定にはメタキャラクタが使用する事ができます。
尚 prompt が on になっていると1ファイルづつ転送するかどうか確認します。
	ftp> mget s*
	mget sh39660?
	mget smdbs ? y
	200 PORT command successful.
	150 Opening BINARY mode data connection for smdbs (xx.xx.xx.xx) (6189 bytes).
	226 Transfer complete.
	6189 bytes received in 0.065 seconds (92 Kbytes/s)

mput ローカルファイル名...
ローカルマシン上の複数ファイルをリモートマシン上のカレントディレクトリにコ ピーします。
ファイル指定にはメタキャラクタが使用する事ができます。 尚 prompt が on になっていると1ファイルづつ転送するかどうか確認します。

prompt
mget/mput コマンド(multiple コマンド)で、ファイル転送の確認を行う/行わな いを切り替えます。

lcd [ディレクトリ名]
ローカルマシン上のワーキング・ディレクトリを変更します。
ディレクトリ名を指定しなければ、そのユーザのホーム・ディレクトリに変更します。

cd [ディレクトリ名]
リモートディレクトリ・リモートマシン上のワーキング・ディレクトリを変更しま す。

pwd
リモートマシン上の現在のワーキング・ディレクトリを表示します。

mkdir ディレクトリ名
リモートマシン上にディレクトリを作成します。

rmdir ディレクトリ名
リモートマシン上のディレクトリを削除します。

dir [リモートディレクトリ名][ローカルファイル]
リモートディレクトリの詳細なファイル一覧を表示します。
リモートディレクトリの指定がなければカレントディレクトリの 詳細なファイル一覧を表示します。 ローカルファイルの指定があればそのファイルに出力します。

ls [リモートディレクトリ名] [ローカルファイル名]
リモートディレクトリのファイル一覧を表示します。 リモートディレクトリの指定がなければカレントディレクトリの詳細な ファイル一覧を表示します。
ローカルファイルの指定があればそのファイルに出力します。

help [コマンド]
コマンドの使用方法を表示します。同様に ? があります。

【実行例】
サーバ osaka に接続(ユーザ名は yakoshi, これはローカルホストと同じ)し、 ファイルの大きさを確認した後、サーバの aaa をローカルの local としてコピーする 例。
	$ ftp osaka
	onnected to osaka.
	220 osaka FTP server (OSF/1 Version 5.60) ready.
	Name (osaka:yakoshi):        # 表示されているユーザ名以外でログインする場合は、入力が必要
	331 Password required for yakoshi.      
	Password:
	230 User yakoshi logged in.
	Remote system type is UNIX.
	Using binary mode to transfer files.
	ftp> ls
	200 PORT command successful.
	150 Opening ASCII mode data connection for file list (xx.xx.xx.xx,4384).
	init
	sh39660
	aaa
	ftp> dir
	drwxrwxrwx   2 root     system       512 Dec  3 19:11 .X11-unix
	-rw-r--r--   1 root     system     15805 Dec  3 15:49 aaa
	-rw-r--r--   1 root     system       382 Dec  3 14:23 ed8974.err
	-rwxr-xr-x   1 root     system    172032 Feb 22  1994 init
	srwxrwxrwx   1 wnn      system         0 Dec  3 19:11 jd_sockV4
	-rwxr-xr-x   1 root     system    658990 Dec  3 12:06 pak
	-rw-r--r--   1 root     system        51 Dec  3 10:26 sh39660
	-rw-r--r--   1 patent   system      6189 Dec  5 10:44 smdb-:0.0.defaults
	-rw-r-----   1 yakoshi  system         0 Dec  5 13:49 x
	226 Transfer complete.
	ftp> get aaa local
	get aaa local
	200 PORT command successful.
	150 Opening BINARY mode data connection for aaa (xx.xx.xx.xx,4388) (15805 bytes)
	.
	226 Transfer complete.
	15805 bytes received in 0.19 seconds (83 Kbytes/s)
	ftp> quit

.netrc のフォーマット
ログインディレクトリに .netrc がある場合、ftp を実行直後その内容に 従って自動的に ftp コマンドを実行することができます。

まず .netrc のファイル属性は 600 (-rw-------) にしておきます。 これはセキュリティ保護の観点から規定されています。
ファイルの内容は大きく2つに分かれ、ログインに関する情報とマクロ定義部 分です。 ログインに関する情報は、自動実行を行いたい接続先とそのユーザ、パスワー ドを記述します。
続いてマクロを定義します。マクロは macdef で始まり、先頭がタブで始まる 行は継続とみなされ、空行で終了します。 init とよばれるマクロは ftp がログイン成功後に実行する内容です。

	$ ls -l ~/.netrc
	-rw-------   1 yakoshi	os2     387 12月05日 14:06 /usr/users/yakoshi/.netrc
	$ cat ~/.netrc
	machine osaka login yakoshi passwd HIMITSU
	macdef init
		cd /tmp            ← この3行は先頭がタブで始まる
		ls
		quit
                                   ← ここは空行
	$ ftp osaka
	Connected to osaka.
	220 osaka FTP server (OSF/1 Version 5.60) ready.
	331 Password required for yakoshi.
	230 User yakoshi logged in.
	cd /tmp
	250 CWD command successful.
	ls
	200 PORT command successful.
	150 Opening ASCII mode data connection for file list (xx.xx.xx.xx,1217).
	jd_sockV4
	ctf-daemon
	mhrepl2078
	mail019672
	Ex02081
	ycos.log.dat
	226 Transfer complete.
	quit
	221 Goodbye.
なお (-n) オプションを指定した場合には自動実行は行なわれません。

Section Next | Prev

Copyright 2007-2018 ycosSystems Network/Body42.html