会话部分与私钥的连接没有问题。但是,当我做一个git克隆,它会给出错误'验证失败'。如何包装,绑定或使连接的会话与git克隆一起工作。我在.NET 4.0下使用NGIT,但不认为这很重要,因为JGIT几乎是一样的。NGIT/JGIT/Git#使用私钥的SSH会话克隆GiT存储库
任何想法?这里
感谢加文
JSch jsch = new JSch();
Session session = jsch.GetSession(gUser, gHost, 22);
jsch.AddIdentity(PrivateKeyFile); // If I leave this line out, the session fails to Auth. therefore it works.
Hashtable table = new Hashtable();
table["StrictHostKeyChecking"] = "no"; // this works
session.SetConfig(table);
session.Connect(); // the session connects.
URIish u = new URIish();
u.SetPort(22);
u.SetHost(gHost);
u.SetUser(gUser);
NGit.Transport.JschSession jschSession = new JschSession(session,u);
if (session.IsConnected())
{
try
{
CloneCommand clone = Git.CloneRepository()
.SetURI(gitAddress)
.SetDirectory(folderToSave);
clone.Call();
// MessageBox.Show(Status, gitAddress, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
// AUth Fail..... ????
}
}
else
{
session.Disconnect();
}
session.Disconnect();
我在凭证提供程序中添加以查看它是否有帮助。 ()) CloneCommand clone = Git.CloneRepository() .SetCredentialsProvider(new CustomCredentialsProvider()) .SetURI(gitAddress) .SetDirectory(folderToSave); clone.Call(); – Gavin 2013-04-29 08:12:38
您使用的是哪个版本的NGit?我注意到的一件事是,从NuGet获得的NGit相当老旧(2011年),因此可能会在修复此问题的错误修复方面落后。就我而言,我根本无法连接,但随后将我的NGit版本更新为[最新来自github](https://github.com/mono/ngit)。 – 2013-11-30 07:38:03