Tamir没有密码的SharpSSH:Auth失败

时间:2013-11-14 08:01:21

标签: c# ssh sftp file-transfer

Sftp sftp = new Sftp(host, user);

// 1.   Generate an SSH-2-RSA public key by PuttyGen 
// 2.   Register the public key on the SFTP server 
// 3.   Save the private key in putty Format 
// 4.   Use WinSCP to connect to the sftp server using the private key generated in the step 3 
// 5.   If the connection works, You will have to load the private key generated in the step 3 and  convert it to OpenSSh format. 
// 6.   Use the private key generated in step 5, make sure that the authentication parameters are right, then test the tamirSftp connection. 
// 7.   Make sure that you have a reference to the three DLL (DiffieHelman, OrgMantalis and TamirSharpSSH ) 

sftp.AddIdentityFile(keyFileName);
sftp.Connect(22);

抛出以下错误:

at Tamir.SharpSsh.jsch.Session.connect(Int32 port) 

密码是否必须连接SFTP机器?

2 个答案:

答案 0 :(得分:1)

我通过在AddIdentityFile()命令中添加密码短语参数来解决此问题。 生成私钥时,您可能添加了密码,并将其包含在通话中。

Sftp sftp = new Sftp(host, user);

//Include it here
sftp.AddIdentityFile(keyFileName, "yourpassphrase");
sftp.Connect(22);

答案 1 :(得分:0)

我对WinSCP不是很确定,但对于Reflection SFTP,您需要提供密码才能连接到服务器并注册公钥。 API文档是否提供了相关数据?