execute WinSCP script with passphrase via Windows Task Scheduler

Advertisement

Jero
Guest

execute WinSCP script with passphrase via Windows Task Scheduler

I am using WinSCP v5.11.2 and am having no luck with executing a WinSCP script via Windows Task Scheduler which contains a passphrase. The script executes without issue from the command line. Here's the script I'm using (w/slight mods for security's sake):

"D:\directory\WinSCP\WinSCP.com" /command "option batch abort" "option confirm off" "open sftp://user@this.domain.com/ -privatekey=""D:\directory\subdir\privatekey.ppk"" -passphrase=""passphrase"" " "cd /custom" "get *.*" "rm *.*" "close" "exit"

I've tried setting up the scheduled task with "D:\directory\WinSCP\WinSCP.com" as the program to run, and the /command switch and its parameters and arguments in the Add arguments field, and setting the Start In field to where I want the downloaded files written. I've also tried putting the script in a batch file and setting the batch file as the program for Task Scheduler to run. No joy in either case. But the script itself runs just fine from the command line, as does the batch file.

This script and the scheduled task had been working fine for months before recently changing to use RSA w/passphrase instead of a password. Task Scheduler isnt offering much in the way of clues about where its failing. The best indicator of the problem is that it sits and waits for a minute or so before finally failing, which makes me think its timing out on something, and most likely the passphrase since that's the new piece.

Any help appreciated!

Thanks,

Jero

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: execute WinSCP script with passphrase via Windows Task Scheduler

Please attach a full session log file showing both the executions by Task Scheduler and by command-line (using the latest version of WinSCP).

To generate the session log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Guest

Re: execute WinSCP script with passphrase via Windows Task Scheduler

Thanks for the quick reply, Martin. The pointer to adding a session log has solved the problem. A review of the log created by the Task Scheduler job showed that it was waiting for authorization to add the remote host key to the cache. I'd already done this during the manual tests from the command line. The issue was that the Task Scheduler job was running as a different user than the user I was logged onto the system as. Both users had admin permissions on the system but, I'd forgotten to setup the connection in WinSCP for the Task Scheduler job's RunAs user.

Many thanks for the help!

Reply with quote

Advertisement

You can post new topics in this forum