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 :
Here is the content of my script to send the file automatically.
The result of this script is :
I'm disappointed, because I really don't know how to do.
Can somebody help me?
Thank you.
I'm still looking for.
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.