Libssh - SSH 消息未实现 [英] Libssh - SSH MESSAGE Unimplemented

查看:97
本文介绍了Libssh - SSH 消息未实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to connect using ssh_connect and libssh, but i get the following error. I have no idea what it means. Any thoughts?

[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; 
}

推荐答案

您在 initialise_ssh() 函数中创建的 ssh_session 对象尚未完全初始化,因此无法像您尝试的那样直接用于创建 sftp 会话.它正在进行一些身份验证,因此套接字在 120 秒超时后关闭,从而引发异常.

The ssh_session object you create in your initialise_ssh() function is not completely initialized yet and thus cannot directly be used to create an sftp session like you try to do. It is laking some authentication and thus the socket is closed after a timeout of 120 seconds, yealding your exception.

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

After your successful ssh_connect() call you should authenticate the host (ssh_is_server_known() function among others) and you must provide a way to authenticate the user: a ssh_userauth_publickey_auto(my_ssh_session, NULL, NULL) would do it if you have public key login set up for the user running your app.

http://api 中选中验证服务器"和验证用户".libssh.org/master/libssh_tutor_guided_tour.html

之后,您就可以使用会话来做一些工作,在您的示例中做一些 sftp.

After that you are set up to use your session to do some work, do some sftp in your example.

这篇关于Libssh - SSH 消息未实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆