Differences

This shows you the differences between the selected revisions of the page.

faq_scheduler 2009-04-01 faq_scheduler 2021-10-07 (current)
Line 1: Line 1:
-====== My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation tool. What am I doing wrong? ====== +====== 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 [[config|configuration storage]], the settings are accessible only for your Windows account. When the script is run from Windows Scheduler, it is typically run under different account that cannot access your configuration.+
-Possible consequences are: +Your script probably depends on your configuration of WinSCP or your local Windows account permissions or environment. 
-  * The script "hangs" because the [[ssh#verifying_the_host_key|host key]] (SFTP or SCP) or [[ftps#certificate|certificate]] (FTPS) is not known by the Scheduler's account and WinSCP asks for its verification. + 
-  * The connection fails, because your script depends on stored session, which is not known by the Scheduler's account. +===== [[config]] Configuration ===== 
-  * Environment variables referenced in script are not resolved, because they are not set by the Scheduler's account.+ 
 +There are two common problems that can be caused by relying on external configuration
 +  * Your script might fail,((Or "hang" in old versions of WinSCP)) because the [[ssh_verifying_the_host_key|host key]] ([[SFTP]] or [[SCP]]) or [[tls#certificate|certificate]] (FTPS, WebDAVS, S3) is not known by the service's account, and WinSCP fails its verification. 
 +  * The connection fails, because your script depends on [[session_configuration#site|site]], which is not known by the service's account; or the local account that runs the service does not have a network access
 + 
 +Note that when using registry as [[config|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. 
 + 
 +To check what [[config|configuration storage]] is used, whether a site name was recognized or under what Windows account the script is running, inspect a beginning of [[logging|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 recognized as a site name. 
 + 
 +<code> 
 +--------------------------------------------------------------------------  
 +WinSCP Version 5.15.3 (Build 9730) (OS 10.0.18362 - Windows 10 Enterprise) 
 +Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\         
 +Log level: Normal 
 +Local account: INTRANET\martin                                           
 +... 
 +Login time: 08 January 2015 08:55:53                                       
 +--------------------------------------------------------------------------  
 +Session name: mysession (Site)                             
 +</code> 
 + 
 +If there was no such site in current configuration storage (Windows registry in this case), ''mysession'' (as passed to ''[[scriptcommand_open|open]]'' command) would be interpreted as host name and the log line would say: 
 + 
 +<code> 
 +Session name: mysession (Ad-hoc session) 
 +</code>
Solutions: Solutions:
-  * Make sure the [[ssh#verifying_the_host_key|host key]] or [[ftps#certificate|certificate]] is verified under the Scheduler's account. With SSH you can [[scripting#hostkey|specify fingerprint of expected hostkey]]. +  * [[scripting#hostkey|Specify fingerprint of expected host key or certificate]] explicitly in the script. ((Alternatively make sure the [[ssh_verifying_the_host_key|host key]] or [[tls#certificate|certificate]] is verified under the service's account.)) 
-  * [[config#transfering_the_configuration|Transfer the stored session]] (or other settings) to the Scheduler's account. +  * Configure your session completely using ''[[scriptcommand_open|open]]'' command, using [[session_url|session URL]] (and [[rawsettings|raw session settings]], if needed), instead of storing [[session_configuration#site|site]]. 
-  * or Use [[config|INI file]] instead of registry to store the configuration. The INI file can be accessed by all accounts.+   * Good practice is to develop your scripts with [[scripting#configuration|configuration isolated from GUI]]. 
 +····* Alternatively use [[config|INI file]] instead of registry to store the configuration to make sure the [[session_configuration#site|site]] (and/or other settings) can be accessed by all accounts. ((You can also [[config#transfer|transfer the site]] (and/or other settings) to the service's account instead.)) 
 + 
 +===== [[variables]] Environment variables ===== 
 + 
 +If your script refers to //user// environment variables, they won't be resolved, if your script run user the service's account. 
 + 
 +===== [[drives]] Mapped Network Drives ===== 
 + 
 +If your script refers to mapped network drives, it may fail if those drives are not mapped under the services' account or if the account does not even have an access to the network drive.  
 + 
 +Use an UNC path to a shared folder, instead of a path to the drive mapped to the shared folder. Make sure the service's account has an access to the shared folder. 
 + 
 +===== [[pageant]] Authentication Agent (Pageant) ===== 
 + 
 +Your script might (intentionally or not) rely on [[ui_pageant|Pageant authentication]], but the Pageant is running in a different Windows session, so it cannot talk to an automated instance of WinSCP (due to Windows session isolation). 
 + 
 +Instead of Pageant authentication, use explicit private key authentication (using ''[[scriptcommand_open|-privatekey]]'' and ''[[scriptcommand_open|-passphrase]]'' switches). 
 + 
 +===== General Recommendations ===== 
 + 
 +If you are able to log in with WinSCP GUI, [[ui_generateurl#script|have it generate a portable script for you]]. The generated script takes care of many of the issues mentioned above. 
 + 
 +When dealing with SSIS see also guide to [[guide_ssis|SFTP task in SSIS]]. 
 + 
 +===== Further Reading ===== 
 + 
 +  * More generic article [[faq_environment|*]] and 
 +  * [[guide_debugging_scheduler|*]].

Last modified: by martin