Need to push backups or files to a remote site via SFTP?
Why not FTP? Because FTP is vulnerable and old and too easy. Let’s get current and mix it up a bit.
SFTP is a secure FTP using an extension of SSH usually over port 22. FTPS uses SSL. FTPS requires additional data channels and certificates for communication. As opposed to SFTP with only one, the data is always secured and is more widely compatible. So, we will use this for my example.
Assume SFTP is already in place and configured and you have tested a working connection. Now you need a cli based task to run on a schedule.
# Load WinSCP .NET assembly
Add-Type -Path “C:\Program Files (x86)\WinSCP\WinSCPnet.dll”
# Set up session options
HostName = “remote.host”
PortNumber = 22
Password = “secret”
SshPrivateKeyPath = “C:\pathto\private.ppk”
SshHostKeyFingerprint = “ssh:host:key:fingerprint”
# Create a new session
$session = New-Object WinSCP.Session
# Transfer files from local to remote
$transferResult = $session.PutFiles(“C:\source\*”, “C:\destination\*”, $False, $transferOptions)
You can use to add rules or actions to do more than just copy files. Like:
# Remove existing part files
Write-Log “Deleted $($partFile.FullName) – part file”
Start-Sleep -Seconds 10
Now you have a working script, how does it run on a schedule? Task Manager!
Create a new task from , 1) Give it a name and 2) assign an execution account*
*The execution account must have “Logon as batch(also, any required privileges to run the task)
Now setup the schedule:
Next, setup the correct parameters for the script to be executed:
-File “location of script”
The rest of the settings are up to you and what is required from the task.
You can test the task by right clicking it and selecting . Check your network card activity from to confirm or the



