I want to connect and asynchronously read a file from a SFTP server using libssh 0.9.5. But this simple working example:
//https://api.libssh.org/master/libssh_tutor_sftp.html#sftp_read
#include <libssh/libssh.h>
#include <libssh/sftp.h>
#include <iostream>
using namespace std;
int main(){
ssh_session sshs = ssh_new();
if(sshs == NULL){
cerr << "Error allocating SSH session: " << ssh_get_error(sshs) << endl;
return SSH_ERROR;
}
ssh_options_set(sshs, SSH_OPTIONS_HOST, "reach");
ssh_options_set(sshs, SSH_OPTIONS_USER, "reach");
//SSH is working fine
int rc = ssh_connect(sshs);
if(rc != SSH_OK){
cerr << "Error connecting to localhost: " << ssh_get_error(sshs) << endl;
return SSH_ERROR;
}
//Now we talking....
sftp_session sftps = sftp_new(sshs);
if(sftps == NULL){
cerr << "Error allocating SFTP session: " << ssh_get_error(sshs) << endl;
return SSH_ERROR;
}
sftp_free(sftps);
ssh_disconnect(sshs);
ssh_free(sshs);
return 0;
}
produces Error allocating SFTP session: sftp_new: Out of memory
.
I can connect to SFTP server on reach@reach
with other software.