Downloading a file

The Secure Copy Protocol (SCP) provides a method to transfer files. It supports both uploading and downloading files.

libssh makes using SCP easy. This chapter's code repository contains an example, ssh_download.c, which shows the basic method for downloading a file over SCP with libssh.

After the SSH session is started and the user is authenticated, ssh_download.c prompts the user for the remote filename using the following code:

/*ssh_download.c excerpt*/    printf("Remote file to download: ");    char filename[128];    fgets(filename, sizeof(filename), stdin);    filename[strlen(filename)-1] = 0;

A new SCP session is initialized by calling the libssh library function ssh_scp_new(), as shown in the following code:

/*ssh_download.c ...

Get Hands-On Network Programming with C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.