I have to download a file from an SFTP server everyday. I have the program which retrieves the file from the server but I was thinking of setting up a cron job (or anything similar) to automate that. We are a Windows shop and need to set up the cron job in Windows.
7 Answers
The windows equivalent to a cron job is a scheduled task.
A scheduled task can be created as described by Alex and Rudu, but it can also be done command line with schtasks
(if you for instance need to script it or add it to version control).
An example:
schtasks /create /tn calculate /tr calc /sc weekly /d MON /st 06:05 /ru "System"
Creates the task calculate, which starts the calculator(calc) every monday at 6:05 (should you ever need that.)
All available commands can be found here: http://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx
It works on windows server 2008 as well as windows server 2003.

- 6,504
- 11
- 47
- 84

- 4,553
- 5
- 33
- 52
-
2thanks for your answer. Any way to see the currently active tasks on the terminal? – gberth Dec 24 '20 at 16:52
-
I love this! Thanks for putting it up here. @gberth schtasks /query shows all of them. The documentation shows many more options. – Casivio Oct 28 '21 at 21:41
- Make sure you logged on as an administrator or you have the same access as an administrator.
- Start->Control Panel->System and Security->Administrative Tools->Task Scheduler
- Action->Create Basic Task->Type a name and Click Next
- Follow through the wizard.

- 24,172
- 16
- 88
- 130
-
17
-
-
2@MáximaAlekz Yes. Action menu -> Import/Export in Task Scheduler. It'll be a xml file. – Krishna Mohan Sep 16 '21 at 08:57
There's pycron which I really as a Cron implementation for windows, but there's also the built in scheduler which should work just fine for what you need (Control Panel -> Scheduled Tasks -> Add Scheduled Task).

- 15,682
- 4
- 47
- 63
-
1
-
2https://pypi.org/project/python-crontab/ seems like a maintained solution. – gberth Oct 29 '21 at 15:33
If you don't want to use Scheduled Tasks you can use the Windows Subsystem for Linux which will allow you to use cron jobs like on Linux.
To make sure cron is actually running you can type service cron status
from within the Linux terminal. If it isn't currently running then type service cron start
and you should be good to go.

- 3,807
- 3
- 33
- 50
I would like to thank @Vincent Stevenson, @s-hunter
Go to Control Panel --> Administrative Tools --> Task Scheduler--> Create Task
Task Scheduler, Create Task
Give the Task a title
Go to Actions
Go to CMD to find the path,
Python, import sys, sys.executable
(this tells you what the Program/script field should be populated with: "some path with Appdata mostly")
like:C:\Users\admin\AppData\Local\Programs\Python\Python38-32\python.exe
Arguments: name of the python script (like run.py)
Start in: dir location of python script (like:C:\Users\admin\Documents\my_python_project)
Go to Triggers, schedule as you like
Test the script by running it

- 111
- 9
For those wanting to use cron in Windows 10/11 with WSL (Windows Subsystem for Linux)
Here are the steps needed:
- Install a linux distribution
- Setup crontab
- Create Windows scheduled task so WSL gets run on startup
1. Install a linux distribution
Open a powershell (admin) terminal. Run
wsl --list --online
Choose one the distros available and install one by running
wsl --install -d <Distro>
2. Setup crontab
Open a powershell (admin) terminal. Run
wsl
You should be in the bash linux distro command line now (first time you might be prompted to create a user/pass. Do so). Run
sudo service cron status
To see if cron is running. If it isn't, run
sudo service cron start
Check again the status, it should be running now.
To edit the cron job, run
crontab -e
For example (backup the pic directory at 20:58 everyday):
58 20 * * * rsync -av /mnt/c/Users/jlo/Pictures/ /mnt/c/Users/jlo/PicBackup/$(date +\%Y\%m\%d\%H\%M\%S)/
Save and exit
3. Create a Windows scheduled task so WSL gets run on startup
a) In order for the Windows scheduled task to run WSL on startup without requiring to enter a password every time it runs the 'service start cron' command, you need to edit visudo by running:
sudo visudo
And adding at the bottom of the file the following:
%sudo ALL=NOPASSWD: /usr/sbin/service cron start
Save and exit.
b) Create a scheduled task
Open Start > Type 'Task scheduler' > Create basic task > Trigger: 'when the computer starts' > Action 'Start a program' > C:\Windows\System32\wsl.exe > In the 'Add arguments' field, add
sudo /usr/sbin/service cron start
Save the task. It should now be listed among the other tasks in the Task scheduler.
And you're good to go. I suggest restarting the machine and checking if cron is running (PS admin terminal > wsl > sudo service cron status) and if it's running, configure and test your first cron job. Enjoy!
Some sources I used to figure this out:

- 2,157
- 2
- 17
- 23
There are also cmdlets in powershell for this:
The linked example:
PS C:\> $actions = (New-ScheduledTaskAction -Execute 'foo.ps1'), (New-ScheduledTaskAction -Execute 'bar.ps1')
PS C:\> $trigger = New-ScheduledTaskTrigger -Daily -At '9:15 AM'
PS C:\> $principal = New-ScheduledTaskPrincipal -UserId 'DOMAIN\user' -RunLevel Highest
PS C:\> $settings = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable -WakeToRun
PS C:\> $task = New-ScheduledTask -Action $actions -Principal $principal -Trigger $trigger -Settings $settings
PS C:\> Register-ScheduledTask 'baz' -InputObject $task

- 2,290
- 1
- 16
- 29