This is an old revision of the document!
My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation service. What am I doing wrong?
You probably depend on your configuration of WinSCP. Note that when using registry as configuration storage, the settings are accessible only for your Windows account. When the script is run from Windows Scheduler, SSIS, DTS or other automation service, it is typically run under different (service) account that cannot access your configuration.
Possible consequences are:
- The script fails (or “hangs”), because the host key (SFTP or SCP) or certificate (FTPS) is not known by the service’s account, and WinSCP fails (or asks for) its verification.
- The connection fails, because your script depends on site, which is not known by the service’s account.
- Environment variables referenced in script are not resolved, because they are not set by the service’s account.
- Access to files on mapped network drives fails, because the drives are not mapped for the service’s account.
Advertisement
To check what configuration storage is used, whether a site name was recognised or under what Windows account the script is running, inspect a beginning of session log. For example, following log shows that the configuration was read from Windows registry, the script was running under local account martin
and mysession
was recognised as a site name.
-------------------------------------------------------------------------- WinSCP Version 5.0.2 (Build 1456) (OS 5.1.2600 Service Pack 3) Configuration: HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\ Local account: INTRANET\martin Login time: 07 October 2011 08:55:53 -------------------------------------------------------------------------- Session name: mysession (Site)
If there was no such site in current configuration storage (Windows registry in this case), mysession
(as passed to open
command) would be interpreted as host name and the log line would say:
Session name: mysession (Ad-hoc session)
Solutions:
- Specify fingerprint of expected host key or certificate explicitly in the script.1
- Configure your session completely using
open
command, using session URL (and raw session settings, if needed), instead of storing site.- Alternatively use INI file instead of registry to store the configuration to make sure the site (and/or other settings) can be accessed by all accounts.2
- Good practice is to develop your scripts with configuration isolated from GUI.
Advertisement
When dealing with SSIS see also guide to SFTP task in SSIS.
See also more generic article on making WinSCP work in a new environment (operating system, machine, user account, network) and Debugging transfer task running in Windows Scheduler, SSIS or other automation service.
- Alternatively make sure the host key or certificate is verified under the service’s account.Back
- You can also transfer the site (and/or other settings) to the service’s account instead.Back