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: Change remote path before Session.Open(SessionOptions)

WinSCP is not trying to access a root. It's trying to access the home directory of your remote account. If your account has an inaccessible root set as the home directory, then it should be fixed on the server.
UATO

Apparently it is possible to define it in the RawSettings of SessionOptions using the not yet documented property RemoteDirectory. Got here checking the .ini file and finding what property was saving this information.
UATO

Change remote path before Session.Open(SessionOptions)

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