SSH主机密钥指纹...与模式不匹配...在C#中使用WinSCP .NET程序集下载文件时 [英] SSH host key fingerprint ... does not match pattern ... when using WinSCP .NET assembly in C# to download files

查看:363
本文介绍了SSH主机密钥指纹...与模式不匹配...在C#中使用WinSCP .NET程序集下载文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个C#应用程序(如果可以正常运行,希望最终创建Windows服务),以便使用SCP从服务器下载文件(我仅限于SCP).我正在使用WinSCP .NET程序集(v 5.15.3).

I'm writing a C# app (want to eventually create a Windows service if I can get this working) to download files from a server using SCP (I am limited to SCP as the only option). I am using the WinSCP .NET assembly (v 5.15.3).

我在PC和服务器之间建立了SSH隧道,因此以下操作可从命令行进行:

I have an SSH tunnel between my PC and the server, so the following works from the command line:

ssh user:server

在我的代码中设置SshHostKeyFingerprint时遇到问题.

I'm running in to a problem when setting the SshHostKeyFingerprint in my code.

WinSCP.SessionOptions options = new WinSCP.SessionOptions();

options.HostName = "ip address";
options.Password = "password";
options.PortNumber = 22;
options.UserName = "username";
options.Protocol = WinSCP.Protocol.Scp;
options.SshHostKeyFingerprint = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkVu2A3SLLdTulOQ1XyGY......"; //full ssh key    

为了方便阅读,我已经缩短了SSH密钥.

I've shortened the SSH key for easier reading.

分配SshHostKeyFingerprint时,出现以下错误:

When assigning the SshHostKeyFingerprint I get the following error:

SSH主机密钥指纹"ssh-rsa 2048 AAAAB3NzaC1yc2EAA ......"不匹配模式/(((ssh-rsa | ssh-dss | ssh-ed25519 | ecdsa-sha2-nistp(256 | 384 | 521 ))(| |))?(\ d +)?(([[0-9a-f] {2}(:|-)){15} [0-9a-f] {2} | [0-9a- zA-Z +/] {43} =)(;(((ssh-rsa | ssh-dss | ssh-ed25519 | ecdsa-sha2-nistp(256 | 384 | 521))(|-))?(\ d +)? (([[0-9a-f] {2}(:|-)){15} [0-9a-f] {2} | [0-9a-zA-Z +/] {43} =))*/

SSH host key fingerprint "ssh-rsa 2048 AAAAB3NzaC1yc2EAA......" does not match pattern /((ssh-rsa|ssh-dss|ssh-ed25519|ecdsa-sha2-nistp(256|384|521))( |-))?(\d+ )?(([0-9a-f]{2}(:|-)){15}[0-9a-f]{2}|[0-9a-zA-Z+/]{43}=)(;((ssh-rsa|ssh-dss|ssh-ed25519|ecdsa-sha2-nistp(256|384|521))( |-))?(\d+ )?(([0-9a-f]{2}(:|-)){15}[0-9a-f]{2}|[0-9a-zA-Z+/]{43}=))*/

我想我分配了错误的SSH密钥(我尝试了客户端和服务器的公共密钥).谁能指出我正确的方向?谢谢.

I guess I'm assigning a wrong SSH key (I have tried both client and server public keys). Can anyone point me in the right direction? Thanks.

注意:我确实尝试过使用批处理文件来执行此操作,但是如果没有登录服务器,就无法按计划运行它.

Note: I did try doing this with a batch file but I couldn't run that on a schedule without the server being logged in.

推荐答案

SessionOptions.SshHostKey**Fingerprint** 是SSH主机密钥的指纹.您正在使用完整主机密钥(您甚至在评论中说了).

What should go to SessionOptions.SshHostKey**Fingerprint** is a fingerprint of the SSH host key. You are using a full host key (what you even say in the comment).

另请参见WinSCP常见问题解答在哪里可以获取用于授权服务器的SSH主机密钥指纹?

See also WinSCP FAQ Where do I get SSH host key fingerprint to authorize the server?

WinSCP GUI可以为您生成正确的代码模板,包括指纹(假设您至少登录了一次):

WinSCP GUI can generate a correct code template for you, including the fingerprint (assuming you have logged in at least once):

这篇关于SSH主机密钥指纹...与模式不匹配...在C#中使用WinSCP .NET程序集下载文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆