Topic "Automation - powershell - host key not verified"

Author Message
JeremyNac

Guest


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 :
Code:
PS c:\Program Files (x86)\WinSCP> powershell c:\myscript.ps1


Here is the content of my script to send the file automatically.
Code:

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 :
Code:
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.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Set Session.SessionLogPath and inspect the log for host keys.
Post the log, if it does not help.
_________________
Martin Prikryl
vik

Guest


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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License