AlmaLinux 9.2 SFTP によるファイルを転送するサンプル

環境
AlmaLinux 9.2

概要
SFTP サーバー機能は AlmaLinux ではデフォルトで有効になっていますが、もし有効になっていない場合は
[/etc/ssh/sshd_config] に [Subsystem sftp /usr/libexec/openssh/sftp-server] の行を追加して
[sshd] をリロードします。

形式
sftp [オプション] [ユーザー@ホスト名]

操作例
1.サーバに接続する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ sftp alma@node01.cft.com
alma@node01.cft.com's password: # ログインユーザーのパスワード
Connected to node01.cft.com.
sftp>
$ sftp alma@node01.cft.com alma@node01.cft.com's password: # ログインユーザーのパスワード Connected to node01.cft.com. sftp>
$ sftp alma@node01.cft.com
alma@node01.cft.com's password: # ログインユーザーのパスワード
Connected to node01.cft.com.
sftp>

2.リモートのカレントディレクトリを表示する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> pwd
Remote working directory: /home/alma
sftp> pwd Remote working directory: /home/alma
sftp> pwd
Remote working directory: /home/alma

3.ローカルのカレントディレクトリを表示する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> !pwd
/home/redhat
sftp> !pwd /home/redhat
sftp> !pwd
/home/redhat

4.リモートのカレントディレクトリのファイル一覧を表示する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> ls -l
sftp> ls -l
sftp> ls -l

5.ローカルのカレントディレクトリのファイル一覧を表示する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> !ls -l
sftp> !ls -l
sftp> !ls -l

ディレクトリ移動する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> cd public_html
sftp> pwd
sftp> cd public_html sftp> pwd
sftp> cd public_html
sftp> pwd

6. ローカルのファイルをリモートにリネームアップロードする

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> put sample.txt info.txt
sftp> ls -l
sftp> put sample.txt info.txt sftp> ls -l
sftp> put sample.txt info.txt
sftp> ls -l

6. ローカルの複数ファイルをリモートに一括アップロードする

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> put *.txt
sftp> ls -l
sftp> put *.txt sftp> ls -l
sftp> put *.txt
sftp> ls -l

7. リモートのファイルをローカルにダウンロードする
sftp> get cft.txt

リモートの複数ファイルをローカルに一括ダウンロードする

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> get *.txt
sftp> get *.txt
sftp> get *.txt

8. リモートのカレントディレクトリにディレクトリ作成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> mkdir cftdir
sftp> ls -l
sftp> mkdir cftdir sftp> ls -l
sftp> mkdir cftdir
sftp> ls -l

リモートのカレントディレクトリ内のディレクトリ削除

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sftp> rmdir cftdir
sftp> ls -l
sftp> rmdir cftdir sftp> ls -l
sftp> rmdir cftdir
sftp> ls -l

 

AlmaLinux 9

Posted by arkgame