我正在尝试使用 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 session 。它缺乏一些身份验证,因此套接字在 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中检查“验证服务器”和“验证用户”
在您设置好使用 session 做一些工作之后,在您的示例中做一些 sftp。
关于c - Libssh - SSH MESSAGE 未实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26113690/