Skip to content

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:

  1. 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:

Command Prompt
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:28
2024/12/10 10:44:33 INFO Licensed for: Ultimate
Enter Password:
2024/12/10 10:44:36 INFO Testing connection to sftp://monitor02@10.0.0.24
The key of 10.0.0.24:22 is unknown. Do you want to add this key to known_hosts (y/n): y
2024/12/10 10:44:51 INFO Connection successful

  1. 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:

Command Prompt
C:\> echo pass> C:\connect\job1_pass
C:\> connect test sftp -h 10.0.0.24 -l monitor02 --password-file c:\connect\job1_pass
2024/12/10 11:30:58 INFO License valid to: 2026-04-13 18:06:28
2024/12/10 11:30:58 INFO Licensed for: Ultimate
2024/12/10 11:30:58 INFO Testing connection to sftp://monitor02@10.0.0.24
2024/12/10 11:31:01 INFO Connection successful
C:\> type C:\connect\job1_pass
ENC:CTQlUh3CIF4vwjYgjJ54PMpGMx+cjp6k4VA6Hy5AOuA=

  1. 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\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
  1. 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.

Command Prompt
C:\> c:\connect\job1.bat
C:\> 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.log
C:\> type c:\connect\job1.log
2024/12/10 15:36:12 INFO License valid to: 2026-04-13 18:06:28
2024/12/10 15:36:12 INFO Licensed for: Ultimate
2024/12/10 15:36:12 INFO Using flag file: c:\connect\job1_tmp
2024/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=1
2024/12/10 15:36:18 INFO File deleted file=c:\data\file2.zip sftpSessionID=3
2024/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=2
2024/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
  1. 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.

  1. Verify the Task
  1. In Task Scheduler, right-click your task Job1 and select Run.
  2. Check the results of your task C:\connect\job1.log to ensure it runs correctly.