Post a reply

Options
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)

Options

Topic review

martin

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.
vyom

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.