【问题标题】:Libssh - SSH MESSAGE UnimplementedLibssh - 未实现的 SSH 消息
【发布时间】:2016-11-30 07:36:12
【问题描述】:

我正在尝试使用 ssh_connect 和 libssh 进行连接,但出现以下错误。我不知道这意味着什么。有什么想法吗?

[2014/09/30 00:53:00.015877, 2] channel_open:  Creating a channel 43 with 64000 window and 32768 max packet
[2014/09/30 00:53:00.050776, 1] ssh_packet_unimplemented:  Received SSH_MSG_UNIMPLEMENTED (sequence number 3)
[2014/09/30 00:54:59.949316, 1] ssh_socket_exception_callback:  Socket exception callback: 1 (0)
[2014/09/30 00:54:59.949483, 1] ssh_socket_exception_callback:  Socket error: disconnected
Error allocating SFTP session: Socket error: disconnected

这是代码

** Initialises SSH Session **/ 
ssh_session initialise_ssh(char* host, int port) {

  ssh_session my_ssh_session;
  int verbosity = SSH_LOG_PROTOCOL;

  my_ssh_session = ssh_new();

  ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, host);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);

  rc = ssh_connect(current_session);
  if (rc != SSH_OK)
  {
    fprintf(stderr, "Error connecting host: %s\n",
            ssh_get_error(current_session));

  return my_ssh_session; 
}

【问题讨论】:

    标签: c networking ssh


    【解决方案1】:

    您在 initialise_ssh() 函数中创建的 ssh_session 对象尚未完全初始化,因此不能像您尝试的那样直接用于创建 sftp 会话。它缺少一些身份验证,因此套接字在 120 秒超时后关闭,发出您的异常。

    在您成功调用 ssh_connect() 后,您应该验证主机(ssh_is_server_known() 函数等)并且您必须提供一种验证用户的方法:ssh_userauth_publickey_auto (my_ssh_session, NULL, NULL) 如果您为运行您的应用程序的用户设置了公钥登录,就会这样做。

    勾选http://api.libssh.org/master/libssh_tutor_guided_tour.html中的“Authenticating the server”和“Authenticating the user”

    在你设置好使用你的会话做一些工作之后,在你的例子中做一些 sftp。

    【讨论】:

      【解决方案2】:

      您正在函数内部创建 my_ssh_session。它的范围仅限于函数 initialise_ssh。而是使用指针,或者将要初始化的会话对象作为参数发送。

      void initialise_ssh(char* host, int port, session* my_ssh_session_ptr) {
      
        int verbosity = SSH_LOG_PROTOCOL;
      
        *my_ssh_session_ptr = ssh_new();
      
        ssh_options_set(*my_ssh_session_ptr, SSH_OPTIONS_HOST, host);
        ssh_options_set(*my_ssh_session_ptr, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
        ssh_options_set(*my_ssh_session_ptr, SSH_OPTIONS_PORT, &port);
      
        rc = ssh_connect(current_session);
        if (rc != SSH_OK)
        {
          fprintf(stderr, "Error connecting host: %s\n",
                  ssh_get_error(current_session));
      
      
      }
      

      【讨论】:

      • 尝试添加示例。事实上,您的回答相当无用,因为它可以用多种方式解释
      • ssh_session 已经是指针类型,所以它的作用域不限于initialise_ssh函数。
      猜你喜欢
      • 1970-01-01
      • 2012-02-11
      • 2015-03-06
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多