PS, Winscp: "New-WinSCPSession : Exception calling "Open" with "1" argument(s): "SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set."

janhoedt
janhoedt used Ask the Experts™
on
Hi,

I'd like to use winscp but do not have a fingerprint. Yes, I know that's a security risk but not where I use it.

This is the tool https://gallery.technet.microsoft.com/WinSCP-PowerShell-Module-ee1601ff



How can I find a way around it?
J.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dan McFaddenSystems Engineer

Commented:
What protocol are you using, SFTP or SCP?  If SFTP, you can switch to just the FTP protocol and then no finger print is required.

Can you post the script throwing the error?

Dan

Author

Commented:
Not sure, the default one, guess that's scp.
There is no error, it just asks for a fingerprint which I do not have.
Systems Engineer
Commented:
You control the protocol by setting the Session Options in the script.  There are 2 ways of doing this:

1.
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Ftp
        HostName = $ftpServer
        PortNumber = 21
        UserName = $userName
        Password = $passWord
}

Open in new window


Here you directly declare the protocol in the Session Options property array.

2.
$sessionUrl = "ftp://"+$userName+":"+$passWord+"@"+$ftpServer+"/"
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.ParseUrl($sessionUrl)

Open in new window


Here, you declare the protocol (also ftp) by building a string that is then consumed by the Session Options using the ParseUrl method.

Reference link:  https://winscp.net/eng/docs/library_sessionoptions

Dan
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
is wnscp ftp? (!)
Dan McFaddenSystems Engineer

Commented:
To quote the WinSCP website:


WinSCP is a popular SFTP client and FTP client for Microsoft Windows!
Copy file between a local computer and remote servers using
FTP, FTPS, SCP, SFTP, WebDAV or S3 file transfer protocols.

So yes, WinSCP can be used with several file transfer protocols, FTP being one of them.

Dan

Author

Commented:
Apparently we use sftp, what is not working with the commands here.

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::sFtp
        HostName = $ftpServer
        PortNumber = 22
        UserName = $userName
        Password = $passWord
}

Error is:
SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set. (raised by: New-WinSCPSession)

New-WinSCPSession -SessionOption $sessionOptions

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial