2014-09-30 65 views
4

我试图使用ssh_connect和libssh进行连接,但出现以下错误。我不知道它是什么意思。有什么想法吗?Libssh - SSH MESSAGE未实现

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

回答

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

之后,你被设置为使用您的会议做了一些工作,做一些SFTP在你的榜样。

0

您创建的函数内部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)); 


} 
+0

尝试添加示例。事实上,你的回答是相当无用的,因为它可以通过多种方式解释 – Avery 2016-11-08 22:14:02

+0

ssh_session已经是一个指针类型,所以它的作用域并不局限于initialise_ssh函数。 – Martin 2016-11-29 23:25:26