使用Sharp SSH进行系统IOException流读取结束

时间:2012-10-02 08:38:11

标签: c# ssh sftp sharpssh

我目前正面临一个非常奇怪的问题。

我在我的代码中实现了Tamir Gal的Sharp SSH库,以便每个FTP上传一些文件。 当我在调试模式下运行代码时,一切正常。但是当我构建解决方案并使用该构建版本进行尝试时,我得到一个System.IO.IOException:

Tamir.SharpSsh.jsch.JSchException: Session.connect: System.IO.IOException: End of IO  Stream Read at Tamir.SharpSsh.jsch.IO.getByte(Byte[] array, Int32 begin, Int32 length)
at Tamir.SharpSsh.jsch.Session.read(Buffer buf)
at Tamir.SharpSsh.jsch.User.Auth.start(Session session)
at Tamir.SharpSsh.jsch.UserAuthNone.start(Session session)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)
at Tamir.SharpSsh.jsch.SshBase.ConnectSession(Int32 tcpPort)
at Tamir.SharpSsh.jsch.SshBase.Connect(Int32 tcpPort)
at Tamir.SharpSsh.jsch.SshBase.Connect()

看起来数据流存在问题(Hello Captain Obvious!:)),因此程序甚至没有建立完成连接方法。我只是不明白为什么一切都在调试时工作。 dll在构建过程中被正确复制。

代码如下所示:

sftpClient = new Sftp(this.ftpHost, this.ftpUser, this.ftpPassword);
sftpClient.Connect();

所有变量都具有正确的值,我可以在像Filezilla这样的客户端中使用它们连接到SFTP服务器。

如果有人能给我一个暗示或者有类似的问题,我会非常感谢每一条评论。

提前谢谢你们,祝你们度过愉快的一天。

1 个答案:

答案 0 :(得分:19)

我的同事刚刚找到了解决方案:

在SharpSSH中你有3个Dll:

  • Org.Mentalis.Security.dll
  • Tamir.SharpSSH.dll
  • DiffieHellman.dll

因为我从来没有在代码中引用Org.Mentalis.Security.dll我完全忘记在构建过程中复制它。因此,SharpSSH中继的整个安全层无法访问,这就是造成错误的原因。

我希望这个帖子可以帮助其他一些不经意的人。 :)