LoginSignup
6
8

More than 5 years have passed since last update.

TeraTerm scpファイル転送で受信完了まで待つ

Posted at

使っている人は少ないであろうTeraTermマクロで小ネタ一つ。

※TeraTerm for UTF-8 バージョン4.74で動作確認しております。
 (最低でも4.66以上必須)

概要

TeraTermマクロで、ファイルをscp受信する場合、scprecvコマンドが使えます。
しかしこのコマンドは非同期処理ですので、ファイルの受信完了を
待つには仕組みを作る必要があります。

今回はそのファイルの受信完了を待つテクニックです。

考え方は単純にしました。
約1秒毎にローカルファイルのサイズチェックを行って増えてなければ受信完了と見なす。
※注意:受信中にLANケーブルが抜けたりした場合でも、受信完了扱いになります。

実装方法

scprececvコマンドで同期を取る
    filesearch localFile
    if result then
        ; 受信ファイルが存在する場合削除
        filedelete localFile
    endif

    scprecv remoteFile localFile
    ;受信完了確認(scprecvが非同期処理のため)
    mpause 1100
    sizeBef = 0
    :confirm_start
        filestat localFile sizeNow
        if sizeNow = sizeBef then
            goto confirm_end
        else
            mpause 1100
        endif
        sizeBef = sizeNow
        goto confirm_start
    :confirm_end

6
8
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
6
8