Hi,
I'm not being able to change the remote path before opening the session in PowerShell using .NET lib.
The problem is that I don't have access to the root of the remote server and it returns an exception on
Open
function.
Using UI I can define it in advanced settings but I couldn't find how to do it using the .Net assembly lib.
Code example:
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{}
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $HostName
$sessionOptions.PortNumber = $PortNumber
$sessionOptions.UserName = $UserName
$sessionOptions.Password = $Password
$sessionOptions.SshPrivateKeyPath = $SshPrivateKeyPath
$sessionOptions.SshHostKeyFingerprint = $SshHostKeyFingerprint
$sessionOptions.AddRawSettings('ProxyMethod', $ProxyMethod)
$sessionOptions.AddRawSettings('ProxyHost', $ProxyHost)
$sessionOptions.AddRawSettings('ProxyPort', $ProxyPort)
$session = New-Object WinSCP.Session
try {
# Connect
$session.Open($sessionOptions) # ERROR WHEN DON'T HAVE ACCESS TO ROOT
# Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.GetFiles($remote, $local, $False, $transferOptions)
} finally {
# Disconnect, clean up
$session.Dispose()
}
It works fine as long as there is not this specific situation.
Thanks