Authentication Failed

Advertisement

Guest

Authentication Failed

I am using this:
# Path to WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
# Session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "blah.com"
    UserName = "XXXXX"
    Password = "XXXXX"
    SshHostKeyFingerprint = "ecdsa-sha2-nistp256 256 xx:xx:xx etc"
}
 
$session = New-Object WinSCP.Session
 
try {
    # Open SFTP session
    $session.Open($sessionOptions)
 
    # Upload file (local -> remote)
    $transferResult = $session.PutFiles(
        "C:\doz\", # local path (can be wildcard)
        "/New/" # remote folder or file path
    )
 
    # Throw if any transfer failed
    $transferResult.Check()
}
finally {
    $session.Dispose()
}
The error I am getting is:
Exception calling "Open" with "1" argument(s): "Authentication failed.
Authentication log (see session log for details):
Using username "XXXXX".
Access denied.
Authentication failed."
At C:\it.info\winscp.ps1:17 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
What I am trying to figure out is that where is the authentication failing in the process. I know the credentials are good because I can manually use them, so I have to assume it has something to do with the SshHostKeyFingerprint, so I think I need to know which key should I be using in the screen shot.

Screenshot_8.png

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,882
Location:
Prague, Czechia

Re: Authentication Failed

It's definitely not the SshHostKeyFingerprint.
Please post session log files both from the code and from successful "manual" login with the same credentials.

Reply with quote

crughp
Joined:
Posts:
1

Re: Authentication Failed

martin wrote:

It's definitely not the SshHostKeyFingerprint.
Please post session log files both from the code and from successful "manual" login with the same credentials.

The logs are easy to get from the manual login, but I am not sure where they populate from the scripted task. Can you shed some light on that for me please?

Reply with quote

Advertisement

You can post new topics in this forum