2014-09-30 63 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