Topic "powershell and open hostkey switch help please"

Author Message



I'm trying to use winscp from powershell to upload a file to an sftp server. What I'm doing works when I run the commands one at a time, but the -hostkey switch seems to get ignored when running the actual script. Can someone please help me understand what I'm doing wrong?

Here's my script:

$starttime = Get-Date
write-output "**** script start $starttime ****"
Set-Location "C:\Program Files (x86)\WinSCP"
.\ /command "option batch continue" "option confirm off" "open -hostkey=""ssh-rsa 2048 b9:ca:61:17:cd:93:76:9f:dd:bb:77:50:84:b5:bd:bc""" "put C:\install\scripts\test.txt" "exit"
$finishtime = Get-Date
write-output "**** script finish $finishtime ****"

And here's the output:

**** script start 10/12/2011 11:27:09 ****
batch continue
confirm off
Searching for host...
Connecting to host...
The server's host key was not found in the cache. You have no guarantee that the server is the computer you think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 b9:ca:61:17:cd:93:76:9f:dd:bb:77:50:84:b5:bd:bc
If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
Continue connecting and add host key to the cache?
(Y)es, (N)o, C(a)ncel, (C)opy Key: Cancel
Host key wasn't verified!
Authentication failed.
Unknown command '2048'.
Unknown command 'b9:ca:61:17:cd:93:76:9f:dd:bb:77:50:84:b5:bd:bc'.
No session.
**** script finish 10/12/2011 11:27:09 ****

I've tried different options with 'confirm' and 'batch' and I've tried different things with quotes but what I have there I believe to be correct. Any help would really be appreciated.

Many thanks,

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
I do not see anything wrong about your command.
What version of WinSCP are you using? Make sure you use the latest (stable) one.
Martin Prikryl
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
Basic PowerShell example added
More examples (and syntax highlighting) coming soon.
Martin Prikryl

You can post new topics in this forum


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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License