How to: Challenge response in PowerShell Script?
Here's the barebones code generated by WinSCP:
# Load WinSCP .NET assembly Add-Type -Path "WinSCPnet.dll" # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Webdav HostName = "example.com" PortNumber = 443 UserName = "username" Password = "password" WebdavSecure = $True } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Your code } finally { $session.Dispose() }
When connecting from the Windows app, I looked in the log & saw this:
. 2018-10-04 14:42:00.919 auth: Got challenge (code 401). . 2018-10-04 14:42:00.919 auth: Got 'Basic' challenge. . 2018-10-04 14:42:00.919 auth: Trying Basic challenge... . 2018-10-04 14:42:00.919 auth: Accepted Basic challenge.
. 2018-10-04 14:45:59.609 ah_post_send (#1), code is 401 (want 401), WWW-Authenticate is Basic realm="example.com" . 2018-10-04 14:45:59.609 auth: Got challenge (code 401). . 2018-10-04 14:45:59.609 auth: Got 'Basic' challenge. . 2018-10-04 14:45:59.609 auth: Trying Basic challenge... . 2018-10-04 14:45:59.609 auth: No challenges accepted. . 2018-10-04 14:45:59.609 sess: Closing connection. . 2018-10-04 14:45:59.609 sess: Connection closed. . 2018-10-04 14:45:59.609 Request ends, status 401 class 4xx, error line: . 2018-10-04 14:45:59.609 Could not authenticate to server: rejected Basic challenge . 2018-10-04 14:45:59.609 Request ends. . 2018-10-04 14:45:59.609 Asking user: . 2018-10-04 14:45:59.609 Error listing directory '/Your Files'. ("Authentication failed.","Could not authenticate to server: rejected Basic challenge") < 2018-10-04 14:45:59.609 Script: Error listing directory '/Your Files'. < 2018-10-04 14:45:59.609 Script: Authentication failed. < 2018-10-04 14:45:59.609 Could not authenticate to server: rejected Basic challenge . 2018-10-04 14:45:59.609 Script: Failed > 2018-10-04 14:45:59.796 Script: exit . 2018-10-04 14:45:59.796 Script: Exit code: 1 . 2018-10-04 14:45:59.796 sess: Destroying session.