Libssh - SSH MESSAGE Not implemented

I am trying to connect using ssh_connect and libssh, but I am getting the following error. I have no idea what that means. Any suggestions?

[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 

here is the code

 ** 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; } 
+5
source share
2 answers

The ssh_session object created in your initialise_ssh () function is not yet fully initialized and therefore cannot be used directly to create an sftp session, as you are trying to do. It performs authentication and, therefore, the socket closes after a timeout of 120 seconds, giving your exception.

After a successful call to ssh_connect (), you must authenticate the host (for example, ssh_is_server_known ()), and you must provide a way to authenticate the user: ssh_userauth_publickey_auto (my_ssh_session, NULL, NULL) will do this if you have a public key for logging in to the user, launching your application.

Check "Server Authentication" and "User Authentication" at http://api.libssh.org/master/libssh_tutor_guided_tour.html

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

+1
source

You create my_ssh_session inside the function. Its scope is limited by the initialise_ssh function. Instead, use pointers or send a session object to be initialized as a parameter.

 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
source

Source: https://habr.com/ru/post/1203680/


All Articles