Differences
This shows you the differences between the selected revisions of the page.
2013-04-23 | 2013-05-07 | ||
beta tag (martin) | Converting to .NET Assembly (martin) | ||
Line 7: | Line 7: | ||
Establishes connection to given host. Use [[session_url|session URL]] or name of the [[session_configuration#site|site]] (stored session) &beta. To open site, stored in folder, use path syntax “folder/site”. Using session URL is preferred as it makes your script independent on the persisted configuration. | Establishes connection to given host. Use [[session_url|session URL]] or name of the [[session_configuration#site|site]] (stored session) &beta. To open site, stored in folder, use path syntax “folder/site”. Using session URL is preferred as it makes your script independent on the persisted configuration. | ||
- | Note that to allow the session be opened automatically without interaction, you need to make sure you provide all details, including all credentials. Generally, you need to provide a password in your [[session_url|session URL]] or [[session_configuration#site|site]]. With [[ssh|SSH]] you may alternatively use passphrase-less private key or use [[ui_pageant|Pageant]]. With SSH and [[ftps|FTPS]] you need to [[scripting#hostkey|verify the host or certificate]]. | + | Note that to allow the session be opened automatically without interaction, you need to make sure you provide all details, including all credentials. Generally, you need to provide a password in your [[session_url|session URL]] or [[session_configuration#site|site]]. With [[ssh|SSH]] you may alternatively use passphrase-less private key or use [[ui_pageant|Pageant]]. With SSH and [[ftps|FTPS]] you need to [[scripting#hostkey|verify the host or certificate]].· |
Switches: | Switches: | ||
Line 33: | Line 33: | ||
</code> | </code> | ||
+ | ===== Converting to .NET Assembly ===== | ||
+ | When [[library_from_script|converting script to .NET Assembly]], map ''open'' command to ''[[library_session_open|Session.Open]]'' method. The ''Session.Open'' accepts instance of ''[[library_sessionoptions|SessionOptions]]'' class, which needs to be populated according to parameters and switches of ''open'' command. | ||
+ | Parameters mapping: [[session_url|Session URL]] in command parameter ''session_url'' needs to be separated to its components, which are to be stored into ''SessionOptions.HostName'' (''host'' component), ''SessionOptions.UserName'' (''username''), ''SessionOptions.Password'' (''password''), ''SessionOptions.PortNumber'' (''port'') and ''SessionOptions.Protocol'' (''sftp|ftp|ftps|scp://''). | ||
+ | |||
+ | There is no direct mapping for opening stored session/site using ''site'' parameter, becase .NET assembly [[library_from_script#default_config|does not share configuration]] with graphical/scripting mode. You need to configure all your session settings directly in your code (using ''[[library_sessionoptions|SessionOptions]]'' class). | ||
+ | |||
+ | Switches mapping: | ||
+ | ^ Switch ^ Mapping ^ | ||
+ | | ''-privatekey'' | Set ''[[library_sessionoptions|SessionOptions.SshPrivateKeyPath]]''. | | ||
+ | | ''-timeout'' | Set ''[[library_sessionoptions|SessionOptions.Timeout]]''. | | ||
+ | | ''-hostkey'' | Set ''[[library_sessionoptions|SessionOptions.SshHostKeyFingerprint]]''. | | ||
+ | | ''-certificate'' | Set ''[[library_sessionoptions|SessionOptions.SslHostCertificateFingerprint]]''. | | ||
+ | | ''-passive'' | Set ''[[library_sessionoptions|SessionOptions.FtpMode]]'' to ''FtpMode.Passive'' for ''on'' or ''FtpMode.Active'' for ''off''. | | ||
+ | | ''-implicit'' | Set ''[[library_sessionoptions|SessionOptions.FtpSecure]]'' to ''FtpSecure.Implicit''. | | ||
+ | | ''-explicitssl'' | Set ''[[library_sessionoptions|SessionOptions.FtpSecure]]'' to ''FtpSecure.ExplicitSsl''. | | ||
+ | | ''-explicittls'' | Set ''[[library_sessionoptions|SessionOptions.FtpSecure]]'' to ''FtpSecure.ExplicitTls''. | | ||
+ | | ''-rawsettings'' | Call ''[[library_sessionoptions|SessionOptions.AddRawSettings]]'' for every key/value pair in switch parameters. | | ||
+ | |||
+ | For example, following script snippet: | ||
+ | |||
+ | <code winscp> | ||
+ | open sftp://martin:mypassword@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
+ | </code> | ||
+ | |||
+ | maps to following PowerShell code: | ||
+ | |||
+ | <code powershell> | ||
+ | $sessionOptions = New-Object WinSCP.SessionOptions | ||
+ | # sftp:// | ||
+ | $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp | ||
+ | $sessionOptions.HostName = "example.com" | ||
+ | $sessionOptions.UserName = "martin" | ||
+ | $sessionOptions.Password = "mypassword" | ||
+ | # -hostkey | ||
+ | $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
+ | |||
+ | $session = New-Object WinSCP.Session | ||
+ | # Connect | ||
+ | $session.Open($sessionOptions) | ||
+ | </code> |