通过公密钥对的方式,SFTP连接异常,提示auth fail

JackSeamanly 2016-04-18 04:06:24
局域网内连接是正常的,用工具连接也是正常的,但是通过程序连接客户那边的服务器时提示auth fail。每次在sshSession.connect();这句代码这里就报错了。
下面是连接方法,privateKey参数是私钥的地址。
哪位大神遇到过类似的问题,帮帮小弟。
public bool connect(String sftpip, int sftpport, String sftpusername, String privateKey, String passphrase)
{
try
{

JSch jsch = new JSch();

jsch.addIdentity(privateKey, passphrase); //private key authentication

Session sshSession = jsch.getSession(sftpusername, sftpip, sftpport);

if (sshSession == null)
{
MessageBox.Show("session is null");
}

Hashtable foo = new Hashtable();
foo.Add("StrictHostKeyChecking", "no"); //不驗証 HostKey
//foo.Add("userauth.gssapi-with-mic", "no");

sshSession.setConfig(foo);
sshSession.setTimeout(10000);//KevinStaticInitData.getFtpConnectTimeOut()) * NumberConstant.INT_1000);

sshSession.connect();
Channel channel = sshSession.openChannel("sftp");
channel.connect();
//sftp = (ChannelSftp) channel;
channel.disconnect();
sshSession.disconnect();
}
catch (Exception ex)
{
m_sEx = ex.Message;
MessageBox.Show(ex.Message);
return false;
}
return true;
}


...全文
1862 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_43054663 2018-11-05
  • 打赏
  • 举报
回复
账号是什么问题
JackSeamanly 2016-04-28
  • 打赏
  • 举报
回复 1
自己定一下。 最终找到问题是服务器那边账号的问题,删除账号后重建一个账户就OK了。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧