CentOS Stream 10
Sponsored Link

FTP サーバー : FTP クライアント CentOS2025/02/04

 

クライアントコンピューターから FTP サーバーにファイル転送します。
CentOS Stream クライアントを例にします。

[1] FTP クライアントをインストールします。
[root@dlp ~]#
dnf -y install lftp
[2] 任意の一般ユーザーでログインして 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            6 Feb 04 08:47 public_html
-rw-r--r--    1 1000     1000       701707 Feb 04 08:47 test.py

# ローカルホストのカレントディレクトリのファイル一覧表示
lftp cent@www.srv.world:~> !ls -l
total 12
-rw-r--r--. 1 redhat redhat 4017 Feb  4 08:48 test2.txt
-rw-r--r--. 1 redhat redhat 4925 Feb  4 08:48 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

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

# ローカルホストのファイルをリモートホストにアップロード
lftp cent@www.srv.world:~> put test.txt
4925 bytes transferred
Total 2 files transferred
lftp cent@www.srv.world:~> ls
drwxr-xr-x    2 1000     1000            6 Feb 04 08:47 public_html
-rw-r--r--    1 1000     1000       701707 Feb 04 08:47 test.py
-rw-r--r--    1 1000     1000         4925 Feb 04 08:50 test.txt

# ローカルホストの複数ファイルをリモートホストに一括アップロード
lftp cent@www.srv.world:~> mput test.txt test2.txt
8942 bytes transferred
Total 2 files transferred
lftp cent@www.srv.world:~> ls
drwxr-xr-x    2 1000     1000            6 Feb 04 08:47 public_html
-rw-r--r--    1 1000     1000       701707 Feb 04 08:47 test.py
-rw-r--r--    1 1000     1000         4925 Feb 04 08:51 test.txt
-rw-r--r--    1 1000     1000         4017 Feb 04 08:51 test2.txt

# [get] の際にファイル上書きを許可する
lftp cent@www.srv.world:~> set xfer:clobber on 

# リモートホストのファイルをローカルホストにダウンロード
lftp cent@www.srv.world:~> get test.py
701707 bytes transferred

# リモートホストの複数ファイルをローカルホストに一括ダウンロード
lftp cent@www.srv.world:~> mget test.txt test2.txt
8942 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            6 Feb 04 08:47 public_html
-rw-r--r--    1 1000     1000       701707 Feb 04 08:47 test.py
-rw-r--r--    1 1000     1000         4925 Feb 04 08:51 test.txt
-rw-r--r--    1 1000     1000         4017 Feb 04 08:51 test2.txt
drwxr-xr-x    2 1000     1000            6 Feb 04 08:52 testdir

# リモートホストのカレントディレクトリ内のディレクトリ削除
lftp cent@www.srv.world:~> rmdir testdir
rmdir ok, `testdir' removed
lftp cent@www.srv.world:~> ls
drwxr-xr-x    2 1000     1000            6 Feb 04 08:47 public_html
-rw-r--r--    1 1000     1000       701707 Feb 04 08:47 test.py
-rw-r--r--    1 1000     1000         4925 Feb 04 08:51 test.txt
-rw-r--r--    1 1000     1000         4017 Feb 04 08:51 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            6 Feb 04 08:47 public_html
-rw-r--r--    1 1000     1000       701707 Feb 04 08:47 test.py
-rw-r--r--    1 1000     1000         4925 Feb 04 08:51 test.txt

# リモートホストの複数ファイル一括削除
lftp cent@www.srv.world:~> mrm test.py test.txt
rm ok, 2 files removed
lftp cent@www.srv.world:~> ls
drwxr-xr-x    2 1000     1000            6 Feb 04 08:47 public_html

# ![command] で任意のコマンド実行
lftp cent@www.srv.world:~> !cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
.....
.....

# 終了
lftp cent@www.srv.world:~> quit
関連コンテンツ