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 3 years have passed since last update.

SFTP環境構築 - WinSCP

Posted at

WinSCP

WinSCP を使ってコマンドラインから SFTP のファイル転送を自動実行できるようにします。

サイト設定

まず WinSCP を GUI で起動します。

Login 画面で [New Site] をクリックし、各項目を入力した後に [Save] で保存します。

image.png

[Site name] は任意の名前を指定し、[Save password] にチェックを入れて [OK] で進みます。

image.png

作成した Login 情報をダブルクリックし接続します。

image.png

Warning が出た場合は [Yes] で進みます。

image.png

[Password] を入力して [OK] で進みます。

image.png

ログインできることを確認したら WinSCP を閉じます。
鍵認証の場合は別途必要な設定を行います。

スクリプト設定

次で設定するバッチファイルから呼び出します。

script_test.txt
# バッチモードをオン
option batch on
# 確認の無効化
option confirm off
# リモートのディレクトリ移動
cd /home/admin/sftp_data
# バイナリモード
option transfer binary
# アップロード
put C:\Apps\WinSCP\test_data.txt
# ダウンロード
get test_data2.txt C:\sftp
# 終了処理
close
exit

バッチファイル

[Site name] が admin@192.168.0.99 の場合です。

script_test.bat
c:
cd \apps\winscp
winscp.exe /console /script=script_test.txt /log=C:\temp\winscp.log admin@192.168.0.99

作成したバッチファイルを実行して正常に動作することを確認します。

スケジュール化

Windows の [タスク スケジューラ] にバッチファイルを登録します。

image.png

トリガーの時間調整を行い正常に動作することを確認します。

以上で完了です。

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?