To resolve error "Could not agree host key algorithm" while scripting PowerShell using .NET assembly

Advertisement

vyom
Joined:
Posts:
1

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
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
}
Kindly help me in resolving this error.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,041
Location:
Prague, Czechia

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.

Reply with quote

Advertisement

You can post new topics in this forum