Automation - powershell - host key not verified

Advertisement

JeremyNac
Guest

Automation - powershell - host key not verified

Hi everybody,

I'm new to Winscp.
I try to send file automatically with Winscp on a SFTP server.
When I connect manually with the GUI, I have no problem : I can connect, send files, get files, ...

But now, I want to send file automatically (with schedulded tasks) using Powershell.
To do it, I execute this command :
PS c:\Program Files (x86)\WinSCP> powershell c:\myscript.ps1

Here is the content of my script to send the file automatically.
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 = "xxx.xxx.xxx.xxx"
    $sessionOptions.UserName = "my_user"
    $sessionOptions.Password = "my_password"
    $SessionOptions.SshPrivateKeyPath = "c:\my_private_key.ppk"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1023 95:5d:61:f4:c3:bb:1d:54:29:0e:55:6d:e5:c1:c8:26"
 
    $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("c:\testfile.txt", "./", $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
}

The result of this script is :
The host key was not verified

I'm disappointed, because I really don't know how to do.
Can somebody help me?

Thank you.
I'm still looking for.

Reply with quote

Advertisement

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

Re: Automation - powershell - host key not verified

Set Session.SessionLogPath and inspect the log for host keys.
Post the log, if it does not help.

Reply with quote

vik
Guest

uploading files from my local to SFTP using powershell scrip

i want to upload files everyday to SFTP CLIENT USING POWERSHELL AND THEN AUTOMATE IT USING TASK SHEDULER.....IM NEW TO THIS KIND OF TASKS.......COULD YOU PLS HELP ME OUT....I TRIED SOME OF THE SCRIPTS BUT I DONT KNOW ITS NOT WORKING AT ALL....CAN ANYONE HELP ME OUT PLS.

Reply with quote

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

Re: uploading files from my local to SFTP using powershell scrip

vik wrote:

i want to upload files everyday to SFTP CLIENT USING POWERSHELL AND THEN AUTOMATE IT USING TASK SHEDULER.....IM NEW TO THIS KIND OF TASKS.......COULD YOU PLS HELP ME OUT....I TRIED SOME OF THE SCRIPTS BUT I DONT KNOW ITS NOT WORKING AT ALL....CAN ANYONE HELP ME OUT PLS.
Start a new thread, show us what you have tried and what problems are you facing.

Reply with quote

Advertisement

You can post new topics in this forum