Topic "powershell and open hostkey switch help please"

Author Message
capt_rob

Guest


Hello,

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"
.\WinSCP.com /command "option batch continue" "option confirm off" "open USERNAME:PASSWORD@SFTP.SERVER.com -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...
Authenticating...
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,

Rob
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Basic PowerShell example added
https://winscp.net/eng/docs/library#powershell
More examples (and syntax highlighting) coming soon.
_________________
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