Skip to content
Advertisement

scp .tar file from remote machine using C program & libssh

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:

JavaScript

Advertisement

Answer

Create a local file using either open() or fopen(), then feed in the raw data using write() or fwrite(). When finished, call close() or fclose().

Updated your code-snippet, not compile tested, but gives you the idea.

The remote read should be repeated until the whole file has been received, also, you might receive chunks that are smaller than sizeof (t_buffer), so do not write out more data than you received.

JavaScript
Advertisement