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

martin

Re: Multiple connections using single sessionOptions

This looks like a simple PowerShell programming question, not a WinSCP question. Are you looking for this?
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::$Protocol
    HostName = $HostName
    PortNumber = $PortNumber
    UserName = $UserName
}
if($ConnectionType -eq 'SftpSSH')
{
    $sessionOptions.SshHostKeyFingerprint = $SshHostKeyFingerprint
    $sessionOptions.SshPrivateKeyPath =  $SshPrivateKeyPath
    $sessionOptions.PrivateKeyPassphrase = $PrivateKeyPassphrase
}
if($ConnectionType -eq 'Ftp')
{
    $sessionOptions.Password = $Password
}
if($ConnectionType -eq 'Active')
{
    $sessionOptions.FtpMode = [WinSCP.FtpMode]::$FtpMode
}


Though I do not see the point of the "Active" type. It should be merged with the "Ftp" type:
if($ConnectionType -eq 'Ftp')
{
    $sessionOptions.Password = $Password
    $sessionOptions.FtpMode = [WinSCP.FtpMode]::$FtpMode
}