Re: To resolve error "Could not agree host key algorithm" while scripting PowerShell using .NET assembly
Can you connect in WinSCP GUI? Please post logs both from the GUI and the .NET assembly.
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
}