Load them from a configuration file in your PowerShell code.
See https://winscp.net/eng/docs/guide_protecting_credentials_for_automation#powershell
See https://winscp.net/eng/docs/guide_protecting_credentials_for_automation#powershell
First, you should not do this. Coupling the assembly with WinSCP application configuration can cause you lots of troubles. The assembly is deliberately isolated from WinSCP application by default.
There's nothing that you cannot configure usingSessionOptions
class. Either using its properties, for basic options; or usingSessionOptions.AddRawSettings
method, for advanced settings.
Anyway, to answer your question:
- SetSession.DefaultConfiguration
tofalse
(to couple the assembly with WinSCP configuration);
- Make sure the assembly shares the configuration with WinSCP. Particularly note that WinSCP uses registry to store configuration by default. So make sure the assembly runs under the same account that you have your stored session/site configured with. Or use INI file instead (useSession.IniFilePath
);
- SetSessionOptions.HostName
to the name of your stored session/site (this is undocumented and unsupported). Note that this works only, if the name does not contain any characters with special meaning in URLs.
winscp.exe [mysession] /synchronize [local_directory] [remote_directory] [/defaults]