Libssh – SSH MESSAGE未实现

我正在尝试使用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; } 

您在initialise_ssh()函数中创建的ssh_session对象尚未完全初始化,因此无法像您尝试那样直接用于创建sftp会话。 它正在进行一些身份validation,因此套接字会在超时120秒后关闭,然后再处理您的exception。

在成功调用ssh_connect()之后,您应该对主机(ssh_is_server_known()函数等)进行身份validation,并且您必须提供一种方法来validation用户:如果您具有公钥登录集,则ssh_userauth_publickey_auto(my_ssh_session,NULL,NULL)将执行此操作为运行您的应用程序的用户。

在http://api.libssh.org/master/libssh_tutor_guided_tour.html中查看“validation服务器”和“validation用户”

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

您正在函数内创建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)); }