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: Password using XML config file

It seems that you have identified that you were using wrong (PowerShell-escaped) password in the XML config file:
WinSCP getting password from xml file
Autocp

Password using XML config file

Hello all!
I have successfully created a syntax that uses the WinSCPnet.dll (.NET assembly).
Also, a config.xml file has been created to provide the credentials and start the session.
I do this successfully with everything except the password!

Here is the script that works:
[xml]$Config = Get-Content "*\Config.xml"
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = $Config.Configuration.HostIP
    UserName = $Config.Configuration.UserName
    Password = "Actual Password"
    PrivateKeyPassphrase = $Config.Configuration.PassPhrase
    SshHostKeyFingerprint = $Config.Configuration.FingerPrint
    SshPrivateKeyPath = $Config.Configuration.SshPrivateKeyPath
}

I cannot get it to work by replacing the "Actual Password" with $Config.Configuration.Password. Within the XML file, I have accounted for escape characters. Does anyone know of other reasons why this would not work?
The error message:
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0.

Authentication log (see session log for details):
Using username "Actual Username".
Authenticating with public key "imported-openssh-key" from agent.
Further authentication required
Access denied.
Authentication failed."
At *\PS_winSCP.ps1:25 char:5
+     $session.Open($sessionOptions)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SessionRemoteException

Any help would be greatly appreciated!
Thank you