批处理中调用 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

你可能感兴趣的:(Java)