Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

philcart

Thanks Martin.

Would much prefer a supported solution.

So is anything you could suggest I look into to avoid hard coding hostname, username, password and server fingerprint values in the script?


Cheers
Phil
martin

Re: Using saved sessions in Powershell

Quote from https://stackoverflow.com/q/20353558/850848#20357983:

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 using SessionOptions class. Either using its properties, for basic options; or using SessionOptions.AddRawSettings method, for advanced settings.

Anyway, to answer your question:

- Set Session.DefaultConfiguration to false (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 (use Session.IniFilePath);
- Set SessionOptions.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.
philcart

Using saved sessions in Powershell

Hi

Currently using WinSCP 5.5.4 and I'm automating our SFTP transfer processes using Powershell. So far, everything is working well so far, but I do have one question.

In the WinSCP GUI we have over a dozen saved sites that are used for a variety of transfer operations. From a command-line, we can use these saved sites with this syntax
winscp.exe [mysession] /synchronize [local_directory] [remote_directory] [/defaults]


In all the Powershell examples I've seen, the HostName, UserName Password and Host Fingerprint are hardcoded directly into the script. Is there anyway for me to refer to our currently saved sites from Powershell?


Cheers
Phil