CentOS 7
Sponsored Link

FTPクライアント : CentOS2014/07/20

 
クライアントコンピューターから FTP サーバーにファイル転送します。CentOS クライアントを例にします。
[1] FTP クライアントをインストールします。
[root@dlp ~]#
yum -y install lftp
[2] root ユーザーでの FTP アクセスはデフォルトで禁止になっているため、一般ユーザーで FTP アクセスして利用します。
# lftp [オプション] [ホスト名]

[redhat@dlp ~]$
lftp -u cent www.srv.world

Password:    
# ログインユーザーのパスワード

lftp cent@www.srv.world:~>
# リモートのカレントディレクトリ表示

lftp cent@www.srv.world:~>
pwd

ftp://cent@www.srv.world
# ローカルのカレントディレクトリ表示

lftp cent@www.srv.world:~>
!pwd

/home/redhat
# リモートのカレントディレクトリのファイル一覧表示

lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
-rw-r--r--    1 1000     1000          399 Jul 20 16:32 test.py
# ローカルのカレントディレクトリのファイル一覧表示

lftp cent@www.srv.world:~>
!ls -l

total 12
-rw-rw-r-- 1 redhat redhat 10 Jul 20 14:30 redhat.txt
-rw-rw-r-- 1 redhat redhat 10 Jul 20 14:59 test2.txt
-rw-rw-r-- 1 redhat redhat 10 Jul 20 14:59 test.txt
# ディレクトリ移動

lftp cent@www.srv.world:~>
cd public_html

lftp cent@www.srv.world:~/public_html>
pwd

ftp://cent@www.srv.world/%2Fhome/cent/public_html
# ローカルのファイルをリモートにアップロード

# -a オプションでアスキー転送 (デフォルトはバイナリ転送)

lftp cent@www.srv.world:~>
put -a redhat.txt

22 bytes transferred
Total 2 files transferred
lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
-rw-r--r--    1 1000     1000           10 Jul 20 17:01 redhat.txt
-rw-r--r--    1 1000     1000          399 Jul 20 16:32 test.py
-rw-r--r--    1 1000     1000           10 Jul 20 17:01 test.txt
# ローカルの複数ファイルをリモートに一括アップロード

lftp cent@www.srv.world:~>
mput -a test.txt test2.txt

22 bytes transferred
Total 2 files transferred
lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
-rw-r--r--    1 1000     1000          399 Jul 20 16:32 test.py
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test.txt
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test2.txt
# リモートのファイルをローカルにダウンロード

# -a オプションでアスキー転送 (デフォルトはバイナリ転送)

lftp cent@www.srv.world:~>
get -a test.py

416 bytes transferred
# リモートの複数ファイルをローカルに一括ダウンロード

lftp cent@www.srv.world:~>
mget -a test.txt test2.txt

20 bytes transferred
Total 2 files transferred
# リモートのカレントディレクトリにディレクトリ作成

lftp cent@www.srv.world:~>
mkdir testdir

mkdir ok, `testdir' created
lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
-rw-r--r--    1 1000     1000          399 Jul 20 16:32 test.py
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test.txt
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test2.txt
drwxr-xr-x    2 1000     1000            6 Jul 20 17:16 testdir
226 Directory send OK.
# リモートのカレントディレクトリ内のディレクトリ削除

lftp cent@www.srv.world:~>
rmdir testdir

rmdir ok, `testdir' removed
lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
-rw-r--r--    1 1000     1000          399 Jul 20 16:32 test.py
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test.txt
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test2.txt
# リモートのファイル削除

lftp cent@www.srv.world:~>
rm test2.txt

rm ok, `test2.txt' removed
lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
-rw-r--r--    1 1000     1000          399 Jul 20 16:32 test.py
-rw-r--r--    1 1000     1000           10 Jul 20 17:06 test.txt
# リモートの複数ファイル一括削除

lftp cent@www.srv.world:~>
mrm redhat.txt test.txt

rm ok, 2 files removed
lftp cent@www.srv.world:~>
ls

drwxr-xr-x    2 1000     1000           23 Jul 19 01:33 public_html
# ![command] で任意のコマンド実行

lftp cent@www.srv.world:~>
!cat /etc/passwd

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
...
...
redhat:x:1001:1001::/home/redhat:/bin/bash
# 終了

lftp cent@www.srv.world:~>
quit

221 Goodbye.
関連コンテンツ