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 excerpt*/
ssh_scp scp = ssh_scp_new(ssh, SSH_SCP_READ, filename);
if (!scp) {
fprintf(stderr...