我对SFTP或OpenSSH经验不足。我试图连接到客户的SFTP以上传文件。
我正在使用SSH.NET库 - https://github.com/sshnet/SSH.NET
在我的C#代码中,我将私钥存储在一个字符串变量中:
var key = @"-----BEGIN OPENSSH PRIVATE KEY-----
// snipped
-----END OPENSSH PRIVATE KEY-----
";
MemoryStream keyStream = new MemoryStream(Encoding.UTF32.GetBytes(key));
Renci.SshNet.ConnectionInfo conn = new Renci.SshNet.ConnectionInfo(
host,
port,
username,
new AuthenticationMethod[]
{
new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[]
{
new PrivateKeyFile(keyStream, ""),
}),
});
但是我遇到了一个错误:
无效的私钥文件。
我的问题是,我看到其他密钥以BEGIN RSA
开头,但我的密钥以BEGIN OPENSSH
开头 - 这是问题吗?