以下の内容はhttps://htn20190109.hatenablog.com/entry/2024/08/03/205214より取得しました。


VBA(WinSCP実行)

https://qiita.com/aimoriu/items/a36b231d3fd26b222452
https://ja.osdn.net/projects/winscp/wiki/scripting

 


-- 1.  Linux側でテストファイル作成

mkdir -p /root/test/d{01,02}/dd{01,02}

touch /root/test/d{01,02}/dd{01,02}/hoge.txt
touch /root/test/d{01,02}/dd{01,02}/fuga.txt

LANG=C tree /root/test


-- 2. 開発タブの挿入でボタンを作成
ActiveXコントロールのものを使用する

-- 3. デザインモードONで作成したボタンをダブルクリックするとエディタが開くので下記コードを記載。デザインモードOFFで実行


Option Explicit


Private Sub CommandButton1_Click()

    '画面を更新しない
    Application.ScreenUpdating = False
    '確認メッセージを表示しない
    Application.DisplayAlerts = False
    
    
    Dim wsh As Object
    Dim res As Object
        
        
    '作業フォルダ作成
    Dim basepath As String
    basepath = ThisWorkbook.Path & "\" & Format(Now, "yyyymmdd_hhmmss")
    
    Dim targetpath As String
    targetpath = basepath & "\" & "test"
    
    MkDir basepath
    MkDir targetpath


    
    Open basepath & "\" & "scp.txt" For Output As #1

        Print #1, "option confirm off"
        Print #1, "option transfer automatic"
        
        Print #1, "open root:root@192.168.137.190"
        
        Print #1, "get /root/test/d01/dd01/hoge.txt """ & targetpath & "\"""
        Print #1, "get /root/test/d01/dd01/fuga.txt """ & targetpath & "\"""
        
        Print #1, "get /root/test/d02 """ & targetpath & "\"""
        
        Print #1, "exit"

    Close #1
    

    
    'コマンド実行
    Dim ret As Long
    
    Set wsh = CreateObject("WScript.Shell")

    ret = wsh.Run(Command:="""C:\Program Files\WinSCP\WinSCP.exe"" /script=""" & basepath & "\" & "scp.txt"" /log=""" & basepath & "\" & "scp.log""", WindowStyle:=0, WaitOnReturn:=True)

    
    'エラー判定
    If ret <> 0 Then
      MsgBox ("処理異常発生")
      GoTo errend
    End If
        
    

    MsgBox "処理完了"

errend:
    
    Set res = Nothing
    Set wsh = Nothing
    
    '確認メッセージを表示する
    Application.DisplayAlerts = True
    '画面を更新する
    Application.ScreenUpdating = True
    


End Sub




以上の内容はhttps://htn20190109.hatenablog.com/entry/2024/08/03/205214より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14