Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

SSH HostKey Fingerprint

$
0
0

Hi I am using the code below for SFTP upload to a SFTP server using WinSCP assembly. My code is running on Windows Server 2008 R2 Standard. This code has a line that asks a value for "SshHostKeyFingerprint". Now, I noticed when i connected SFTP server for the first time, a fingerprint showed up, and I had to accept as yes. I believe this fingerprint is stored somewhere in the server.
1. How to find this fingerprint from the system in the format for powershell?
2. Where this fingerprint is located in the server?


------------------
try
{
    # Load WinSCP .NET assembly
    [Reflection.Assembly]::LoadFrom("WinSCP.dll") | Out-Null
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "example.com"
    $sessionOptions.UserName = "user"
    $sessionOptions.Password = "mypassword"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
 
        $transferResult = $session.PutFiles("b:\toupload\*", "./", $FALSE, $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}

------------------








Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>