Windows Scheduler
Sending files to a remote SFTP on a schedule
Section titled “Sending files to a remote SFTP on a schedule”Let’s say we’d like to send all .zip
files from C:\data
folder
to SFTP server 10.0.0.24
using monitor02
user and pass
password.
Moreover we’d like those files to be send automatically every 10 minutes.
Here are the steps to do that:
- SFTP connection test
First we need to test the connection to the remote SFTP server and add it’s host key to known_hosts
.
To do that open Command Prompt and execute:
C:\> connect test sftp -h 10.0.0.24 -l monitor02 -p -2024/12/10 10:44:33 INFO License valid to: 2026-04-13 18:06:282024/12/10 10:44:33 INFO Licensed for: UltimateEnter Password:2024/12/10 10:44:36 INFO Testing connection to sftp://monitor02@10.0.0.24The key of 10.0.0.24:22 is unknown. Do you want to add this key to known_hosts (y/n): y2024/12/10 10:44:51 INFO Connection successful
- Store password in a file
Then we need to store the password in a file and rerun the connection test. To do that open Command Prompt and execute:
C:\> echo pass> C:\connect\job1_passC:\> connect test sftp -h 10.0.0.24 -l monitor02 --password-file c:\connect\job1_pass2024/12/10 11:30:58 INFO License valid to: 2026-04-13 18:06:282024/12/10 11:30:58 INFO Licensed for: Ultimate2024/12/10 11:30:58 INFO Testing connection to sftp://monitor02@10.0.0.242024/12/10 11:31:01 INFO Connection successfulC:\> type C:\connect\job1_passENC:CTQlUh3CIF4vwjYgjJ54PMpGMx+cjp6k4VA6Hy5AOuA=
- Create a Batch File
We need to create a batch file so it can be executed by Task Scheduler. To do that open notepad and paste below command, then save the file as job1.bat
.
c:\connect\connect.exe send sftp ^-h 10.0.0.24 ^-l monitor02 ^--password-file c:\connect\job1_pass ^-s c:\data ^--file-mask "*.zip" ^--delete ^--parallel 3 ^--flag c:\connect\job1_tmp ^--batch ^--no-color >> c:\connect\job1.log
- Test the script
We need to run the C:\connect\job1.bat
script manually. To do that open Command Prompt, and run the .bat file.
C:\> c:\connect\job1.batC:\> c:\connect\connect.exe send sftp -h 10.0.0.24 -l monitor02 --password-file c:\connect\job1_pass -s c:\data --file-mask "*.zip" --delete --parallel 3 --flag c:\connect\job1_tmp --batch --no-color 1>>c:\connect\job1.logC:\> type c:\connect\job1.log2024/12/10 15:36:12 INFO License valid to: 2026-04-13 18:06:282024/12/10 15:36:12 INFO Licensed for: Ultimate2024/12/10 15:36:12 INFO Using flag file: c:\connect\job1_tmp2024/12/10 15:36:12 INFO Sending files to sftp://monitor02@10.0.0.24:2024/12/10 15:36:16 INFO Transferring file=c:\data\file3.zip sftpSessionID=2 targetFolder=2024/12/10 15:36:17 INFO Transferring file=c:\data\file1.zip sftpSessionID=1 targetFolder=2024/12/10 15:36:17 INFO Transferring file=c:\data\file2.zip sftpSessionID=3 targetFolder=2024/12/10 15:36:18 INFO File deleted file=c:\data\file1.zip sftpSessionID=12024/12/10 15:36:18 INFO File deleted file=c:\data\file2.zip sftpSessionID=32024/12/10 15:36:18 INFO File transferred successfully bytesTransferred=1048576 duration=1s663ms transferRate=615.45KB/s file=c:\data\file1.zip sftpSessionID=1 targetFolder=2024/12/10 15:36:18 INFO File transferred successfully bytesTransferred=1048576 duration=1s704ms transferRate=600.89KB/s file=c:\data\file2.zip sftpSessionID=3 targetFolder=2024/12/10 15:36:20 INFO File deleted file=c:\data\file3.zip sftpSessionID=22024/12/10 15:36:20 INFO File transferred successfully bytesTransferred=1048576 duration=3s765ms transferRate=271.96KB/s file=c:\data\file3.zip sftpSessionID=2 targetFolder=2024/12/10 15:36:20 INFO Disconnected sftpSessionID=1 target=sftp://monitor02@10.0.0.24:2024/12/10 15:36:20 INFO Disconnected sftpSessionID=2 target=sftp://monitor02@10.0.0.24:2024/12/10 15:36:20 INFO Removing flag file: c:\connect\job1_tmp
- Add job to Windows Task Scheduler
Open Task Scheduler:
Press Win + R
, type taskschd.msc
, and press Enter.
Create New Folder:
Click Action
> New Folder
Name: SFTP
Go to Folder:
Select the SFTP
folder.
Create a New Task:
Click Action
> Create Task
General Tab:
Name: Job1
Security Options:
Select Run whether user is logged on or not.
Select Do not store password. The task will only have access to local computer resources.
Triggers Tab:
Click New
.
Set Begin the task
to On a schedule
.
Set the Repeat task every
option to 10 minutes
for a duration of Indefinitely
.
Click OK
.
Actions Tab:
Click New
.
Set Action
to Start a Program
.
In Program/script
, browse to your .bat file C:\connect\job1.bat
.
Click OK
.
Conditions Tab:
Uncheck all options.
Settings Tab:
Check Allow task to be run on demand
.
Uncheck all other settings.
If the task is already running
, then Do not start a new instance
.
Click OK
.
- Verify the Task
- In Task Scheduler, right-click your task
Job1
and select Run. - Check the results of your task
C:\connect\job1.log
to ensure it runs correctly.