Windows – How to automate pulling files via putty’s psftp

puttyscheduled-taskwindowswindows-registrywindows-server-2003

I have a Windows Server 2003 box and it is using psftp to connect to a remote linux machine and download files every hour.

Picture 1.png

I have two main challenges with this machine:

First

Scheduled tasks are currently set to run as a user on this box, which I believe requires storing the user's password in the task scheduler. However when the user's password changes the task fails to run. I'd like to have this task always run regardless.

  • I believe the solution to the first problem is to have the scheduled task run as SYSTEM. Is that correct? If so, how do I set this up? Just type SYSTEM in the "Run as" box? And do I need to set a password for SYSTEM because I believe I tried with no password and it said the job did not run because the password was incorrect. Perhaps I am doing this wrong.

Second

Putty requires that the remote key for a server is stored in the registry to verify the server's authenticity. However this seems to be stored on a per-user basis and so if I switch the script to run as a different user it seems the user must run the script interactively the first time so that the key is stored in the registry.

  • Instructions on the putty website mention that keys should be added to the following registry location:

    HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys
    

But judging from "HKEY_CURRENT_USER" I don't think that will be for the SYSTEM user. If I do set up this task to run as SYSTEM, how can I make sure that the appropriate key is stored in the registry for the host? I don't mind manually adding it (there is a perl script to convert a known_hosts file), but where should it go?

ps: myscript.bat just uses psftp.exe to pull files from a remote server. Nothing special. There is no flag to skip checking authorized hosts, and the folks at putty mention that this would be a bad idea anyhow.

Best Answer

I realize there's already an accepted answer for this question, but I thought I'd throw in the answer to where the SYSTEM account's user registry hive is located. It's actually in HKEY_USERS\.DEFAULT which most people incorrectly assume is the default user hive for newly created accounts. More info on the history and background of the key is on Raymond Chen's MSDN blog here:

The .Default user is not the default user