如何将libssh实现为我的编译器可识别的库?我正在使用Visual Studio 2010 C++,并且我已经包含了Boost库而没有任何问题,但我使用Boost进行的过程很奇怪,我可以告诉libssh会有所不同.
我真的不想做一个DLL文件,我想要一个可执行文件,但是我知道DLL文件可以通过.rc脚本嵌入到可执行文件中.(然后提取并加载)
除了Boost之外,我从来没有必要在我的任何项目中包含一个库,我觉得我应该真的知道如何做到这一点.请注意这是libssh而不是libssh2.谢谢.
我从官方教程中使用客户端代码进行直接和反向端口转发:http://api.libssh.org/master/libssh_tutor_forwarding.html
在Ubuntu 16.10上将客户端连接到OpenSSH服务器时,此代码非常有效,即实现了直接和反向端口转发.
但是,请考虑反向端口转发(web_server())的客户端代码,它使用以下调用:
ssh_channel_listen_forward()
ssh_channel_accept_forward()
Run Code Online (Sandbox Code Playgroud)
使用我自己的libssh服务器,问题是客户端在调用中超时,出现ssh_channel_accept_forward()以下错误消息:
"No channel request of this type from server"
Run Code Online (Sandbox Code Playgroud)
也就是说,等待1分钟后,由以下客户端代码打印错误消息:
channel = ssh_channel_accept_forward(session, 60000, &port);
if (channel == NULL)
{
fprintf(stderr, "Error waiting for incoming connection: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
Run Code Online (Sandbox Code Playgroud)
如何在服务器端构建通道请求,以便客户端不会超时ssh_channel_forward_accept()并创建新的转发通道?我没有运气就尝试了大多数API函数......
是否有用于发送此类频道请求的特定API函数?如果没有,我如何完成请求频道的任务?
我在服务器端的代码沿着以下行,其中ssh_channel_listen_forward()请求由以下回调函数捕获:
void global_request(ssh_session session, ssh_message message, void *userdata) {
#ifdef DEBUG
printf("[Debug] global_request()\n");
#endif
struct session_data_struct *session_data = (struct session_data_struct*) userdata;
ssh_message_global_request_reply_success(message, 8080);
const char *addr = ssh_message_global_request_address(message);
int port …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个将连接到 ssh 服务器(我的笔记本电脑)的 C++ 程序。服务器没问题,因为我可以通过腻子连接。虽然到目前为止我写的程序不能。在我的代码中,我使用库 libssh.h 并进行开发,我使用了 Visual Studio 2015。我得到的错误是:crypt_set_algorithms2: no crypto algorithm function found for 3des-cbc 我到目前为止还没有找到任何东西,所以我希望你帮助。我使用的代码:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
int rc;
int port = 22;
int verbosity = SSH_LOG_PROTOCOL;
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, "192.168.1.6");
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "john");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
//ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
// Connect to server
rc = ssh_connect(my_ssh_session);
if (rc != …Run Code Online (Sandbox Code Playgroud) 我在这里发帖是因为我需要一些与libssh相关的代码的帮助.
我在这里阅读了所有官方文档 ,但是如果有人可以点亮我我会很高兴,我仍然不明白我需要做的事情.
其实我想将文件从客户端复制到远程服务器,但我不明白如何使用图书馆libssh和libssh功能SFTP做到这一点.
情况是:ssh会话打开,sftp会话也是打开的,我可以创建一个文件,并使用lib ssh的集成功能从客户端写入服务器.
我没有找到一种简单的方法将文件从客户端复制到服务器,使用简单的函数,如sftp_transfer(sourceFile(如c:\ my document\hello world.txt),RemoteFile(/ home/user/hello world.txt) ),对(读(写)))?
根据我从教程中理解的内容,它首先在远程位置(服务器)创建一个文件,然后用这行代码打开这个文件:
file = sftp_open(sftp, "/home/helloworld.txt",access_type,1);
Run Code Online (Sandbox Code Playgroud)
之后,在服务器上创建文件,然后使用缓冲区写入此创建的文件:
const char *helloworld = "Hello, World!\n";
int length = strlen(helloworld);
nwritten = sftp_write(file, helloworld, length);
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,如果我有一个文件,例如.doc文件,我想将该文件从c:\ mydocument\document.doc传输/上传到远程服务器/home/user/document.doc远程我该怎么办?用这种方法吗?
如何将此文件放入sftp_write()函数中以像示例函数中的helloworld一样发送它?
我可能在编程上不够理解,但我真的试图理解它并且我坚持使用它.
在此先感谢您的帮助
请参阅下面我用于测试的代码示例:
// Set variable for the communication
char buffer[256];
unsigned int nbytes;
//create a file to send by SFTP
int access_type = O_WRONLY | O_CREAT | O_TRUNC;
const char *helloworld = "Hello, …Run Code Online (Sandbox Code Playgroud) 我在 google 上搜索了 "libbssh vs libssh2" ,找不到关于它们之间区别的很好的解释。
主要区别是什么?
我需要的主要功能是复制文件,推荐使用哪个库?
例如,我想打开一个会话和一个通道,然后执行多个不同的命令。我有InitializeSSHSession 和Initialize SSH 通道方法,如下所示。
void Computer::InitializeSSHSession()
{
ssh_session remoteSSHSession = ssh_new();
if ( remoteSSHSession )
{
QString password = this->GetPassword();
QString remoteIP = this->GetIP();
QString userName = this->GetUserNameW();
ssh_options_set(remoteSSHSession, SSH_OPTIONS_HOST, remoteIP.toStdString().c_str());
ssh_options_set(remoteSSHSession, SSH_OPTIONS_LOG_VERBOSITY, &sessionVerbosity);
ssh_options_set(remoteSSHSession, SSH_OPTIONS_PORT, &sessionPort);
ssh_options_set(remoteSSHSession, SSH_OPTIONS_USER, userName.toStdString().c_str());
int remoteConnection = ssh_connect(remoteSSHSession);
if ( remoteConnection == SSH_OK )
{
int authenticateControl = ssh_userauth_password(remoteSSHSession, NULL, password.toStdString().c_str());
if ( authenticateControl == SSH_AUTH_SUCCESS )
{
InitializeSSHChannel(remoteSSHSession);
}
else
{
remoteSSHSession = NULL;
}
}
else
{
remoteSSHSession = NULL;
}
} …Run Code Online (Sandbox Code Playgroud) 我想在我的OSX上玩hydra,但我无法弄清楚问题是什么.
brew info hydra
Run Code Online (Sandbox Code Playgroud)
输出:
hydra: stable 8.3 (bottled), HEAD Network logon cracker which supports
many services https://www.thc.org/thc-hydra/
/usr/local/Cellar/hydra/8.3 (14 files, 1.2M) * Poured from bottle on
2016-08-20 at 15:28:25 From:
https://github.com/Homebrew/homebrew-core/blob/master/Formula/hydra.rb
==> Dependencies Build: pkg-config ? Required: openssl ? Optional: subversion ?, libidn ?, libssh ?, pcre ?, gtk+ ?
==> Options
--with-gtk+ Build with gtk+ support
--with-libidn Build with libidn support
--with-libssh Build with libssh support
--with-pcre Build with pcre support
--with-subversion Build with subversion support
--HEAD Install …Run Code Online (Sandbox Code Playgroud) 我试图将我的程序与 libssh 静态库链接。
以下是我从 libssh 教程复制的简单代码:
//sshtest.c
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
#include <stdlib.h>
int main()
{
ssh_session my_ssh_session;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_free(my_ssh_session);
}
Run Code Online (Sandbox Code Playgroud)
我将库文件放入libssh.a子目录中libs/
然后用命令编译gcc sshtest.c -Llibs -lssh -o sshtest
输出是一堆未定义的引用错误,例如:
libs/libssh.a(wrapper.c.o): In function `crypto_free':
/home/gg/libssh/src/wrapper.c:156: undefined reference to `BN_clear_free'
/home/gg/libssh/src/wrapper.c:157: undefined reference to `BN_clear_free'
libs/libssh.a(libcrypto.c.o): In function `ssh_reseed':
/home/gg/libssh/src/libcrypto.c:77: undefined reference to `RAND_add'
libs/libssh.a(libcrypto.c.o): In function `sha1_init':
/home/gg/libssh/src/libcrypto.c:84: undefined reference to `EVP_MD_CTX_new'
Run Code Online (Sandbox Code Playgroud)
可以通过将动态库文件(libssh.so, libssh.so.4, libssh.so.4.5.0)复制到该libs/文件夹中来解决该问题,但我猜在这种情况下编译器将链接动态库。 …
我正在尝试使用 cmake 从源代码构建 ssh.lib。
为此,我下载了 libssh 0.8.2、Win32OpenSSL_Light-1_1_0i 和 cmake-3.9.0-rc1-win64-x64。
使用 Visual Studio 2017。我已将 open SSL 安装到 c 目录中,然后使用 cmake 分配源和构建路径。生成时,显示错误“配置过程中出错,项目文件可能无效”和
**CMake Error at CMakeLists.txt:335 (install):
install Library TARGETS given no DESTINATION!
Threads_FOUND=
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.9)
should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more
information run …Run Code Online (Sandbox Code Playgroud)