I have written a code which read file from remote device using libssh scp APIs.
I have a specific requirement wherein I want to scp a .tar file from a remote device. I am able to read .tar content into a buffer, but I am not sure how to create .tar file out of that buffer.
Any help would be appreciated.
Thanks.
Code snippet:
char *t_filename, t_buffer[32768];
....
t_rc = ssh_scp_pull_request(t_scp);
switch(t_rc)
{
case SSH_SCP_REQUEST_NEWFILE:
t_filesize = ssh_scp_request_get_size(t_scp);
t_filename = strdup(ssh_scp_request_get_filename(t_scp));
t_filemode = ssh_scp_request_get_permissions(t_scp);
fprintf(stderr, "Receiving file %s, size %d, permisssions 0%o\n", t_filename, t_filesize, t_filemode);
ssh_scp_accept_request(t_scp);
t_rc = ssh_scp_read(t_scp, t_buffer, sizeof(t_buffer));
if(t_rc == SSH_ERROR)
{
fprintf(stderr, "Error receiving file data: %s\n", ssh_get_error(in_session));
ssh_scp_close(t_scp);
ssh_scp_free(t_scp);
return t_rc;
}
fprintf(stderr, "Bytes received = %d\n", t_rc);
FILE *fptr = fopen(t_filename, "w");
if(NULL != fptr)
{
fwrite(t_buffer,sizeof(t_buffer),1,fptr);
fclose(fptr);
}
break;
}