diff options
Diffstat (limited to 'src/cssh.c')
-rw-r--r-- | src/cssh.c | 60 |
1 files changed, 59 insertions, 1 deletions
@@ -12,7 +12,7 @@ #include "msleep.h" -#include "cssh_options.h" +#include "options.h" #include "version.h" static int parse_options_and_arguments( int argc, char *argv[], struct gengetopt_args_info *args_info ) { @@ -807,6 +807,64 @@ int main( int argc, char *argv[] ) } } + for( unsigned int i = 0; i < nof_sessions; i++ ) { + rc = ssh_scp_init( scp[i] ); + if( rc != SSH_OK ) { + fprintf( stderr, "ERROR: Unable to initialize SCP sessions: %s\n", + ssh_get_error( session[i] ) ); + cleanup_sessions( &session, NULL, &scp, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); + } + } + + switch( copy_direction ) { + case CSSH_COPY_DIRECTION_UPLOAD: { + } break; + + case CSSH_COPY_DIRECTION_DOWNLOAD: { + // TODO: we receive files from N hosts, so we should + // have a method to create separate directories or + // files, e.g. file.host1, file.host2, etc. + // or dirs host1/file host2/file. Maybe this depends + // also on whether we specify recursive mode or not + for( unsigned int i = 0; i < nof_sessions; i++ ) { + rc = ssh_scp_pull_request( scp[i] ); + switch( rc ) { + case SSH_SCP_REQUEST_NEWDIR: + // TODO: mkdir in host[i] workspace + break; + + case SSH_SCP_REQUEST_ENDDIR: + // TODO: leave current workspace + break; + + case SSH_SCP_REQUEST_NEWFILE: + // TODO: receive file in workdir of host[i] + break; + + case SSH_SCP_REQUEST_EOF: + // TODO: keep array of eof flags and terminate + // loop if all hosts have terminated + break; + + case SSH_ERROR: + fprintf( stderr, "ERROR: error from remote host '%s': %s\n", + host[i], ssh_get_error( session[i] ) ); + cleanup_sessions( &session, NULL, &scp, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); + break; + + case SSH_SCP_REQUEST_WARNING: + fprintf( stderr, "WARNING: remote host '%s': %s\n", + host[i], ssh_scp_request_get_warning( scp[i] ) ); + cleanup_sessions( &session, NULL, &scp, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); + break; + } + } + } break; + } + cleanup_sessions( &session, NULL, &scp, host, port, nof_sessions, args_info.verbose_given > 0 ); } break; |