1. 程式人生 > >批處理中呼叫 WinSCP 命令列上傳檔案

批處理中呼叫 WinSCP 命令列上傳檔案

@echo off
setlocal enabledelayedexpansion

set ID=AY47C010

REM 設定檔案的路徑
set SHELL_DIR=H:\IDE\eclipse\workspace\XXXX\shell
set CLASSES_DIR=H:\IDE\eclipse\workspace\XXXX\classes
set FTP_PATH=/u01/app/lou/

rem 解析 KSH 檔案,提取呼叫的 Java 類

if not exist %SHELL_DIR%\%ID%.ksh (
    echo エラー:%SHELL_DIR%\%ID%.ksh が存在しないです。
    goto end
)

rem 基礎命令

set COMMAND_STRING="option transfer binary"

set num=0
for /f "eol=# delims== tokens=2,*" %%i in ('type %SHELL_DIR%\%ID%.ksh') do (
    set className=%%i
    if "!className:~-10,10!" == "Controller" (
        set /a num+=1
        set PGMID=!className:~-18,8!
        set SYSID=!className:~-23,3!
        echo !num!. !PGMID!
        set COMMAND_STRING=!COMMAND_STRING! "put %CLASSES_DIR%\com\java\!SYSID!\C!PGMID!Controller.class %FTP_PATH%"
    )
)


echo %COMMAND_STRING%

set WINSCP_EXE=F:\archive\apps\PortableApps\PortableApps\WinSCPPortable\App\winscp\WinSCP.com
%WINSCP_EXE% /console /command "option batch continue" "option confirm off" "open sftp://oracle:[email protected]:22 -hostkey=""ssh-rsa 2048 1d:8e:a1:58:9d:bd:e9:35:5d:8c:69:5c:13:28:8f:ee""" "option transfer binary" "put %SHELL_DIR%\%ID%.ksh %FTP_PATH%" %COMMAND_STRING% "exit"

echo.
echo ----------------------------(完了)----------------------------------

:end

pause