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

Author Message
yoku

Guest


Hi,

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%


IF %ERRORLEVEL% == 0 GOTO OK

echo.
echo !!! ERROR There was a problem during zip procedure. ErrorLevel = %ERRORLEVEL%
echo.
GOTO end

:OK
echo ------------------------Archive Done------------------------ >>%logfile% 2>&1

echo ------------------------Start Uploading------------------------ >>%logfile% 2>&1

"c:\Program Files (x86)\WinSCP\winscp.com" /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

:end
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
Advertisements
yoku

Guest


+ 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 doubleclick on backup.bat
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
yoku wrote:
+ 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 doubleclick on backup.bat

If the batch file does not even execute WinSCP, it's not WinSCP question/problem.

If the actual problem is, that WinSCP is executed, but does not work, see
https://winscp.net/eng/docs/faq_scheduler

You are for sure missing the -hostkey switch, what is covered in the FAQ above and also here:
https://winscp.net/eng/docs/scripting#hostkey
yoku

Guest


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/ssh_host_rsa_key.pub and put it in the command:
"c:\backup\WinSCP\winscp.com" /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 showen key is the same as the GUI shows before firs connect (eg. https://winscp.net/eng/data/media/screenshots/unknown_hostkey.png)

But scheduled task still doesn't work Sad No log records for winscp command, just from .bat (>>%logfile% 2>&1 ) . In attachhemt I upoladed 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
winscp.txt (223.21 KB) [Download]

Description: (none)

Guest




Also I tried to add -certificate switch in open command, but always got an error msg like Unknown switch 'certificate'.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
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\winscp.com" /command ... >>%logfile% 2>&1
yoku

Guest


OMG!
Thank you Martin, it's working now!
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License