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: Authentication Failed

To generate the session log file with .NET assembly, set Session.SessionLogPath.
crughp

Re: Authentication Failed

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?
martin

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.
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.