libssh会话连接超时错误

时间:2014-08-22 13:06:03

标签: libssh

我已经从libSSH下载并编译了libssh 0.6.1 我还将ssh.lib,ssh.dll链接到一个visual c ++项目 下面带代码的库编译并运行正常,
但是当调用ssh_connect()时,它返回-1:超时。
我使用了选项:

  

ssh_options_set(my_ssh_session,SSH_OPTIONS_LOG_VERBOSITY,& verbosity);

打印日志记录,它说:

  

ssh_connect:socket连接现在等待回调工作。
  ssh_connect:超时连接到本地主机。

在我的笔记本电脑上,我安装了FreeSSHd服务器并使用putty工程连接到它。

我的代码,直到错误:

int _tmain(int argc, _TCHAR* argv[])
{

ssh_session my_ssh_session;
int verbosity = SSH_LOG_PROTOCOL;
int port = 22;
int rc;
char *password;
// Open session and set options
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
    exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
// Connect to server
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
    fprintf(stderr, "Error connecting to localhost: %s\n",
        ssh_get_error(my_ssh_session));
    ssh_free(my_ssh_session);
    exit(-1);
}

此代码示例是从A typical SSH session Exmple网站复制的。

1 个答案:

答案 0 :(得分:0)

libssh不支持“localhost”作为网站中所述的参数,而是定义:

 char* host="127.0.0.1";