I currently have a process setup with Task Scheduler on my PC which uses WinSCP to connect to a server and grab a file. My PC is almost always on with Pageant running (already having put in the passphrase), so when the process uses WinSCP to connect to the server it automtically picks up pageant, recognizes my privatekey and connects to the server to grab the file no problem.
However, the issue is my PC has to remain logged in. Occasionally IT will restart our PC's logging me off and preventing my Task from running since I am no longer logged in.
Now, I know you can setup a process to have the Task Scheduler to run even when you are not logged in. However, the problem there is that Pageant would not be running, so when the process runs and attempts to connect to the server using the privatekey it would prompt for the passphrase of my privatekey thus not proceed any further.
WinSCP also does not support including the passphrase at the command line otherwise I would have added that within the options of the Task Scheduler.
What I was hoping would be possible would be to connect to the server by way of VB Script and have it enter the passphrase, connect, and grab the file. This way I can simple create a schedule to run VB Script. Can this be done in VB Script? I found the below script, though I get a compilation error and I am not sure if this script will work for what I need. I was hoping for a more experienced VB Script user to guide me.
However, the issue is my PC has to remain logged in. Occasionally IT will restart our PC's logging me off and preventing my Task from running since I am no longer logged in.
Now, I know you can setup a process to have the Task Scheduler to run even when you are not logged in. However, the problem there is that Pageant would not be running, so when the process runs and attempts to connect to the server using the privatekey it would prompt for the passphrase of my privatekey thus not proceed any further.
WinSCP also does not support including the passphrase at the command line otherwise I would have added that within the options of the Task Scheduler.
What I was hoping would be possible would be to connect to the server by way of VB Script and have it enter the passphrase, connect, and grab the file. This way I can simple create a schedule to run VB Script. Can this be done in VB Script? I found the below script, though I get a compilation error and I am not sure if this script will work for what I need. I was hoping for a more experienced VB Script user to guide me.
Code:
Option Explicit
' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = Protocol_Sftp
.HostName = "bp123.abc.tnt.com"
.UserName = "calvin"
'i'm placing my password for the private here here, though I don't know if that is what it's for
.Password = "abc123"
.SshHostKeyFingerprint = "ssh-rsa 1234 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx rsa-key-20201111"
End With
Dim session
Set session = WScript.CreateObject("WinSCP.Session")
' Connect
session.Open sessionOptions
' Upload files
Dim transferOptions
Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
transferOptions.TransferMode = TransferMode_Binary
Dim transferResult
Set transferResult = session.GetFiles("/folder1/Report.xlsx", "C:\Users\mike\Desktop\", False, transferOptions)
' Throw on any error
transferResult.Check
' Print results
Dim transfer
For Each transfer In transferResult.Transfers
WScript.Echo "Upload of " & transfer.FileName & " succeeded"
Next
' Disconnect, clean up
session.Dispose