0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SFTPのバッチ処理

Posted at

Linxuで構築したSFTPサーバに対して、クライアントのバッチプログラムでSFTPコマンドでファイル取得を行った。

環境

CentOS 7.9
Windows 10

コマンドについて

1.公開鍵認証方式で接続するため、-iに指定した秘密鍵に対応する、公開鍵をログインユーザ(以下ではsftpuser)のホームディレクトリに.ssh/authorized_keysとして配置。

2.初回接続時のホスト鍵を無視するため。StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/nullを設定しています。

3.sftpコマンドの-bには、実行するコマンドを書いたファイルを指定。'-'は標準入力。

Linux

Linuxでは、ヒアドキュメントを使用してコマンドを渡しました。

sftp -b - -i id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null sftpuser@host <<EOS
get FILE SAVE
quit
EOS

Windows

Windowsでは、パイプを通してコマンドを渡しました。

(
echo get FILE SAVE
echo quit
) | sftp -b - -i id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null sftpuser@host 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?