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);

Its throwing following error:

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

Does Password is mandatory to connect SFTP machine?

有帮助吗?

解决方案

I solved this by adding a passphrase parameter to the AddIdentityFile() command. You might have added a passphrase when you generated your private key, include it in your call.

Sftp sftp = new Sftp(host, user);

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

其他提示

I'm not very sure about WinSCP, but for Reflection SFTP, you need to provide password to connect to the server and register public key. Does the API documentation provide any data on this?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top