Post a reply

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)


Topic review


Thanks for the response! Is there any way to capture the server response? I would like to add some logic to say something like
if ($serverResponse -contains $password){
notify me

By capture I mean within the script store it to a variable and check against it.

Re: How do I capture the password expire prompt within WinSCP session logging?

The password expiry is not part of the error. The server didn't indicate anyhow that it closed the connection because of the expired password. It's obvious to a human. But a computer (code) cannot recognize that (without AI).

How do I capture the password expire prompt within WinSCP session logging?

I have try/catch blocks in my script and within the catch block I write to eventviewer to log any exceptions/errors thrown. However, for this one sftp the password was expired and the session log shows the prompt from the server saying password is expired, but the exception thrown doesn't show that - it just says authentication failed. I know its basically the same thing, but i would prefer to accurately catch the server response so when im alerted in eventviewer I can easily see the issue.

. 2020-08-21 10:20:50.606 Prompt (keyboard interactive, "SSH server: Password Authentication", "Enter password for USERNAME", "Password:")

. 2020-08-21 10:20:50.607 Using stored password.
. 2020-08-21 10:20:50.753 Prompt (keyboard interactive, "SSH server: Password Expired", "Your password has expired. Enter new password for USERNAME", "New Password:"1 more)
. 2020-08-21 10:20:50.754 User aborted during keyboard-interactive authentication
. 2020-08-21 10:20:50.755 Attempt to close connection due to fatal exception:
* 2020-08-21 10:20:50.755 **Connection has been unexpectedly closed.** Server sent command exit status 0.
. 2020-08-21 10:20:50.756 Closing connection.
 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 "USERNAME".
Welcome to *********

Authentication failed."
End Error

You can see how under the "NESTED CATCH ERROR" that the exception doesn't clearly show that the password is expired. Anyone know how I can capture that server response from the session instead of searching the log for "password expire"? Here is my code within the catch if that helps
    # Write the error message to the console for visual, but also write to the eventlog for monitoring - note this also pulls errors from .check() in the transfer
    Write-Output "Error: $($_.Exception.Message)"
    $logMessage = $_.Exception.Message
    if ($errorWhitelist -notcontains $logMessage){
       Write-EventLog -LogName Application -Source "External_SFTP_Script" -EventID 101 -EntryType Warning -Message $logMessage
    Add-Content -Path $logFilePath "***NESTED CATCH ERROR****`n $logMessage`nEnd Error"
    Add-Content -Path $logFilePath $Error