Ticket #73 (closed defect)

Opened 9 years ago

Last modified 9 years ago

Receive binary file from remote machine using libssh2 lib

Reported by: anonymous Owned by:
Priority: normal Milestone:
Component: SCP Version:
Keywords: Cc: bagder
Blocked By: Blocks:

Description

Hi,

I am using libssh2_scp_recv() to write a function to receive files from remote machine to local machine.

This code is working fine in case of transfering readable (.txt etc) files. But when any executable binary is received , it is not getting transfered completely.There may be a problem in reading the contents from the opened channel.

Function GetFile?() code is as follows:

int GetFile?(const char *local_path,const char *path,struct stat *sb)
{

long byte = 0 , byte1 = 0;
channel = libssh2_scp_recv(session, path, sb);
printf("Channel returned\n");
if (channel == NULL) {
printf("recv_file(): unable to open channel\n");
try{
char errmsg;
int *errmsg_len = NULL;
int want_buf;

libssh2_session_last_error(session, errmsg, errmsg_len , want_buf);
want_buf = libssh2_session_last_errno(session);

printf("Error String
%s",*errmsg); Conn_UnknownResult; }catch(...){ } return (-1); } printf("Channel opened\n");

char* buffer = new char[sb->st_size];
QByteArray file_content;

libssh2_channel_set_blocking(channel, BLOCK);
while(byte < sb->st_size)
{

byte1 = libssh2_channel_read(channel,buffer,sb->st_size);
byte += byte1;
buffer[byte1] = '\0';
file_content += buffer;

}
QFile file(local_path);
if ((!file.open(QIODevice::WriteOnly?)))

{

printf("unable to open file %s\n",local_path);

if (channel) {

libssh2_channel_free(channel);
channel = NULL;

}

return (-1);

}

file.write(file_content);
printf("local file size = %d\n",file.size());


file.close();
if (channel) {

libssh2_channel_free(channel);
channel = NULL;

}

}

Please let me your inputs why this is not working for a binary file.

Thanks,

Regards,
Chamanesh

Change History

comment:1 Changed 9 years ago by bagder

It works fine with binary files for me. If you need help on using libssh2, don't file a bug report.

Note: See TracTickets for help on using tickets.