在 Win32 SSH 上通过 ForceCommand 使用自定义脚本时,SFTP 不会启动

在 Win32 SSH 上通过 ForceCommand 使用自定义脚本时,SFTP 不会启动

我编写了一个脚本,用于在用户通过 SSH 登录时发送电子邮件警报。它通过 ForceCommand 触发。这在打开终端窗口时工作正常,但 SFTP 不起作用(Bitvise 日志显示“SFTP 通道已打开”,但没有出现 SFTP 窗口)。我在脚本文件中遗漏了什么吗?

来自 sshd_config:

#Run command at login
ForceCommand c:\ProgramData\ssh\login.bat

这是脚本(login.bat)

@echo off

REM For colored text; see :colorEcho below
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)

ipconfig /all
echo:
REM Get current date and time
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
call :colorEcho a0 "User %LOGNAME% connected to %COMPUTERNAME% from %SSH_CONNECTION% at %mydate%_%mytime%"
REM Send alert that user has connected.
c:\BatchFiles\EmailMessage\EmailMessage.exe -s "New Connection to %COMPUTERNAME%" -b "User %LOGNAME% connected to %COMPUTERNAME% from %SSH_CONNECTION% at %mydate%_%mytime%"
echo:
echo:

REM Send original command from SSH so shell will start
cmd %SSH_ORIGINAL_COMMAND%

REM This provides for colored text
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

谢谢你!

相关内容