Password using XML config file

Advertisement

Autocp
Joined:
Posts:
4

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

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum