In my current project. I am working on ssh_scp APIs (more precisely ssh_scp_push_file, ssh_scp_write, ssh_scp_push_directory APIs). Here is the code snipet for it.
rc = ssh_scp_push_file(scp, file_name, size, S_IRUSR | S_IWUSR);
if (rc != SSH_OK) {
fprintf(stderr, "Can't open remote file: %s\n", ssh_get_error(session));
return rc;
}
rc = ssh_scp_write(scp, memblock, size);
if (rc != SSH_OK) {
fprintf(stderr, "Can't write to remote file: %s\n", ssh_get_error(session));
return rc;
}
When I interrupt the scp communication on my Ubuntu 18.04 using a command
$ sudo iptables -I INPUT -s [ip_address] -j DROP
The process completely stops for an unknown time period. Blocking complete process. And never resume the process.
So I want to ask, is there a way to set a timeout, so that if I didn't get the response from the ssh_scp server, it will wait for some time and, on timeout returns some SSH_ERROR and proceeds further. So that it will not block a complete process.