To resolve error "Could not agree host key algorithm" while scripting PowerShell using .NET assembly
Hi, Greetings!!!
I am new to PowerShell scripting and WinSCP as well. My scenario is to compare timestamp off two files from two different directories from WinSCP. Hence I started first making connection with server using PowerShell which is generated by .NET assembly of WinSCP using below code.
WinSCP version is 6.3.1
However, I am getting below error
Kindly help me in resolving this error.
I am new to PowerShell scripting and WinSCP as well. My scenario is to compare timestamp off two files from two different directories from WinSCP. Hence I started first making connection with server using PowerShell which is generated by .NET assembly of WinSCP using below code.
WinSCP version is 6.3.1
However, I am getting below error
Error : Exception calling "Open" with "1" arguments(s): " Could not agree host key algorithm" (available: rsa-sha2-XXX,rsa-sha2-256)
try { # Load WinSCP .NET assembly Add-Type -Path "WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "example.com" UserName = "user" Password = "mypassword" SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # code for comparing timestamp } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }