Differences
This shows you the differences between the selected revisions of the page.
| 2015-11-04 | 2015-11-04 | ||
| c#/vb.net (martin) | session url (martin) | ||
| Line 31: | Line 31: | ||
| ===== Using WinSCP .NET assembly ===== | ===== Using WinSCP .NET assembly ===== | ||
| - | ==== PowerShell ==== | + | ==== [[powershell]] PowerShell ==== |
| In [[library_powershell|PowerShell]] code using [[library|WinSCP .NET library]] you can use ''[[http://technet.microsoft.com/en-us/library/hh849787.aspx|Get-Content]]'' cmdlet to read an XML configuration file. | In [[library_powershell|PowerShell]] code using [[library|WinSCP .NET library]] you can use ''[[http://technet.microsoft.com/en-us/library/hh849787.aspx|Get-Content]]'' cmdlet to read an XML configuration file. | ||
| Line 85: | Line 85: | ||
| </code> | </code> | ||
| - | ==== Visual Studio (C#, VB.NET) ==== | + | ==== [[vs]] Visual Studio (C#, VB.NET) ==== |
| In .NET projects (C#, VB.NET) an application configuration file (''App.config'') is used to store the settings. Though this file contains other configuration that needs to be shared and/or stored in a revision control system. To separate the credentials from other settings, you can link another configuration file like shown below. | In .NET projects (C#, VB.NET) an application configuration file (''App.config'') is used to store the settings. Though this file contains other configuration that needs to be shared and/or stored in a revision control system. To separate the credentials from other settings, you can link another configuration file like shown below. | ||
| Line 160: | Line 160: | ||
| See [[library_ssis#example|SSIS example]]. | See [[library_ssis#example|SSIS example]]. | ||
| + | |||
| + | ==== Session URL ==== | ||
| + | |||
| + | Instead of storing credentials (username and password) individually, you can use a single string, the [[session_url|session URL]] (a kind of "connection string"). This gives you an additional flexibility of changing even protocol by mere configuration. | ||
| + | |||
| + | Use the ''[[library_sessionoptions_parseurl|SessionOptions.ParseUrl]]'' to parse the URL into individual components. | ||
| + | |||
| + | You can change the [[#powershell|above PowerShell example]] as below. | ||
| + | |||
| + | The configuration file: | ||
| + | |||
| + | <code xml> | ||
| + | <Configuration> | ||
| + | <SessionUrl>sftp://martin:mypassword@example.com/</SessionUrl> | ||
| + | </Configuration> | ||
| + | </code> | ||
| + | |||
| + | The code: | ||
| + | |||
| + | <code powershell> | ||
| + | # Read XML configuration file | ||
| + | [xml]$config = Get-Content ".\config.xml" | ||
| + | |||
| + | # Use read credentials | ||
| + | $sessionOptions = New-Object WinSCP.SessionOptions | ||
| + | $sessionOptions.ParseUrl($config.Configuration.SessionUrl) | ||
| + | |||
| + | ... | ||
| + | </code> | ||
| + | |||
| + | You can apply the same technique to the [[#vs|above C# example]]. | ||
| + | |||
| + | Only if you want to encrypt the password as shown in the previous sections, you need to separate the password from the rest of the session %%URL%%. First call the ''SessionOptions.ParseUrl'' and then separately set the ''SessionOptions.Password''. | ||