Batch file -> Script file (AWS) WinSCP window immediately closes

Advertisement

poorman
Joined:
Posts:
3
Location:
Japan

Batch file -> Script file (AWS) WinSCP window immediately closes

I have a batch file to connect to an AWS SFTP server. Download all the files in the root folder to my current directory out\SYOHINMT\<time executed> and copy all the files to \ftp_recieve\
SET BATLOGFILE="%~dp0log\sftp_recieve.log"
SET BATLOGTEMP="%~dp0log\sftp_recieve_tmp.log"
SET yyyyMMdd=%date:/=%
SET hhmmss=%time: =0%
SET hhmmss=%hhmmss:~0,2%%hhmmss:~3,2%%hhmmss:~6,2%
 
mkdir "%~dp0out\SYOHINMT\%yyyyMMdd%_%hhmmss%"
cd    "%~dp0out\SYOHINMT\%yyyyMMdd%_%hhmmss%"
 
"C:\Users\81803\AppData\Local\Programs\WinSCP\WinSCP.exe" /console /script="C:\Users\81803\デスクトップ\rad\conf\sftp_recieve.conf" /ini=nul /log="C:\Users\81803\デスクトップ\rad\log\winscplog.log" >> %BATLOGFILE% 2>&1
 
for /f "delims=" %%a in (%BATLOGTEMP%) do (
  echo %%a >> %BATLOGFILE% 2>&1
  echo "%%a" | find "%200 COMPLETED.%" >NUL
  if not ERRORLEVEL 1 set /a COMPCOUNT=COMPCOUNT+1
)
copy .\* ..\..\..\ftp_recieve\  >> %BATLOGFILE% 2>&1
EXIT
Here is my sftp_recieve.conf script:
option batch on
open sftp://xxxx@xxxx.amazonaws.com:22 -privatekey="C:xx\xxx\keys\xxxx.ppk" -hostkey="ssh-rsa 2048 xxxxxxxxxxx"
get -resume ./*
close
exit
When executing this line, the WinSCP window (CMD) in the batch file immediately closes. I don't even have LOG files for these since it wasn't even given the time to enter the SFTP server
"C:\Users\81803\AppData\Local\Programs\WinSCP\WinSCP.exe" /console /script="C:\Users\81803\デスクトップ\rad\conf\sftp_recieve.conf" /ini=nul /log="C:\Users\81803\デスクトップ\rad\log\winscplog.log" >> %BATLOGFILE% 2>&1
Anyone can help? Each line of code runs smoothly in CMD. Only the problem is when executing the batch file.

Reply with quote

Advertisement

poorman
Joined:
Posts:
3
Location:
Japan

I read this from the documentation. https://winscp.net/eng/docs/executables
I plan to use this batch file in a Windows Scheduler (Task Scheduler).

I used WinSCP.com but it was still the same result. Nothing happening and the console closes right away. I also tried using it with and without /console
"C:\Users\81803\AppData\Local\Programs\WinSCP\WinSCP.com" /console /script="C:\Users\81803\デスクトップ\rad\conf\sftp_recieve.conf" /ini=nul /log="C:\Users\81803\デスクトップ\rad\log\winscplog.log" >> %BATLOGFILE% 2>&1
Could it be because of the Japanese characters in the path?
/script="C:\Users\81803\デスクトップ\rad\conf\sftp_recieve.conf"

Reply with quote

poorman
Joined:
Posts:
3
Location:
Japan

Fixed

Yes, I tried debugging in command prompt (cmd) and now see the errors.

This now fixed by replacing this:
/script="C:\Users\81803\デスクトップ\rad\conf\sftp_recieve.conf"
to this:
/script="%~dp0rad\conf\sftp_recieve.conf"
%~dp0 is the working directory on where the batch file was executed.

Thanks Martin for the guidance. Cheers

Reply with quote

Advertisement

Guest

It was because of the Japanese characters. My batch file is encoded with UTF-8 and it the program cannot read the proper path.

Reply with quote

Advertisement

You can post new topics in this forum