我已经从libSSH下载并编译了 libssh 0.6.1 。
我还将 ssh.lib,ssh.dll 链接到一个可视化 c++ 项目。
带有以下代码的库编译并运行良好,
但在调用 ssh_connect() 时,它返回 -1: Timeout 。
我使用了以下选项:
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
打印日志,它说:
ssh_connect :套接字连接现在等待回调工作。
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);
}
此代码示例从典型的 SSH 会话示例站点复制而来。