Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Thank you Martin, it's working now!

Did you try using an absolute path to the log file? /log=C:\backup\AICBackup.log

Also redirect even WinSCP output to your batch file log:
"c:\backup\WinSCP\" /command  ... >>%logfile% 2>&1

Also I tried to add -certificate switch in open command, but always got an error msg like Unknown switch 'certificate'.

Hi Martin,

Thanks a lot, it's a good starting point. At first, config was read out from registry. Now I exported settings to .ini and moved into WinSCP folder.
. 2017-05-09 13:01:22.093 Configuration: c:\backup\WinSCP\WinSCP.ini

Also I exported pub hostkey with ssh-keyXXXgen -l -f /etc/ssh/ and put it in the command:
"c:\backup\WinSCP\" /command  "open sftp://root:root@server/ -hostkey=""ssh-rsa 2048 1g:f3:e2:bc:35:ff:19:2f:a6:6f:d1:82:e6:af:1c:9c""" "put c:\AIC_Backup\Archive\AIC_Backup.7z /data1/backup/AIC/AIC_Backup.7z" "exit" "/log=AICBackup.log" "/loglevel=1"

The shown key is the same as the GUI shows before first connect e.g:

But scheduled task still doesn't work :( No log records for winscp command, just from .bat (>>%logfile% 2>&1). In attachment I uploaded the log when I run it with clicking on backup.bat. Do you see maybe anything wrong in it?

I'll keep checking for the issue. Thanks

+ info:
If I try to run it from Task Scheduler, it runs but doesn't execute the winscp command. So it's working only if I double click on backup.bat.

Scheduled upload doesn't work from .bat file, win 2012 R2


I have a .bat file with something like this:
@echo off
title Backup
SET logfile=C:\backup\Backup.log
echo ------------------------START Backup------------------------ >>%logfile% 2>&1
date /T  >>%logfile% 2>&1
time /T >>%logfile% 2>&1
if not exist "C:\Backup" mkdir C:\Backup
if not exist "C:\Backup\Archive" mkdir C:\Backup\Archive
echo -----copy----- >>%logfile% 2>&1
xcopy C:\\design\* C:\Backup\design\* /y /s
del /F /Q c:\AIC_Backup\Archive\*
"c:\backup\7-Zip\7z" a -r C:\Backup\Archive\Backup.7z C:\AIC_Backup\*
echo errorlevel: %ERRORLEVEL%
echo !!! ERROR There was a problem during zip procedure. ErrorLevel = %ERRORLEVEL%
GOTO end
echo ------------------------Archive Done------------------------ >>%logfile% 2>&1
echo ------------------------Start Uploading------------------------ >>%logfile% 2>&1
"c:\Program Files (x86)\WinSCP\" /command "open sftp://root:root@server/" "put c:\Backup\Archive\Backup.7z /data1/backup/Backup.7z" "exit" "/log=Backup.log" "/loglevel=1"   
echo ------------------------Uploading Done------------------------ >>%logfile% 2>&1
echo ------------------------Backup Done------------------------ >>%logfile% 2>&1

Working cool, if I run it manually, but unfortunately scheduled task doesn't upload it. Archive is done, just WinSCP upload is not working. There is no log records for uploading (only if I run it by hand). Can anybody help me? Thanks