0
votes

I have been trying to make the scheduler work for the past two days. I am trying to sync a folder from a remote server using WinSCP, however I do not want to keep WinSCP running continuously and am thus running it using a batch file. The batch file is below.

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="WinSCP_log.log" /ini=nul ^
  /command ^
    "open sftp://xxxxxxxxxxxxxxxxx -hostkey=""xxxxxxxxxxxxxxxxxxxxx""" ^
    "cd /data/remotexxxxxx" ^
    "lcd C:\localxxxxx" ^
    "synchronize local" ^

It runs fine when I just run the batch file. When using the Windows Task Scheduler to run every 20 minutes it does not run. However, even in the Scheduler if I double click and run manually it works fine. I even tried converting the batch file to a .exe, but face the same issue there.

The Windows Task Scheduler settings are -

Program/Script: /Directory/sync_winscp.bat Arguments: Start in: /Directory

And similarly for the .exe file

Program/Script: /Directory/sync_winscp.exe Arguments: Start in:

I also tried -

Program/Script: .../Win32/cmd.exe Arguments: /Directory/sync_winscp.bat Start in:

It is running with highest privileges and does not have a timeout.

Update: I also have another .bat file to call python and run a script daily which runs perfectly fine.

1
Provide full paths to all involved files and directories! Does the Scheduled Task run under user context? - aschipfl
In the scheduler, all the paths have been entered as the full address. I'm not sure what you mean by user context. - shbhuk
I was talking about whether or not the checkbox "run script when user is logged on" is ticked... - aschipfl
No, it says run whether user is logged on or not. - shbhuk

1 Answers

0
votes

Edit the task and switch to the Triggers-tab. Select the designated trigger in the list and click Edit-button. Make sure that all of the below is true:

  1. "Begin the task" option is set to "On a schedule" value.
  2. Start date is today, and time is a few minutes later than current.
  3. "Enabled" check-box is checked.

Click OK all the way out to activate the task, then verify at the next run time. All of the above settings are important, but the key here is, the task will NOT run until it gets triggered first. In other words, it will run on schedule only AFTER it gets triggered. This is why start time must be set slightly into the future.