int gmShellPlink::pscp_execute(const gmdString& args){ int i, res; gmdString errmsg; if(!auth_defined) LOGJOBERR("Authentification method are not defined, " "check 'login', 'host' and 'plink_args' parameters!"); if(dump_commands) LOGJOBMSG4( (pCSTR) ("------ pscp_execute ------\n" " cmd=" + pscp_pre + args + "\n" )); for(i=0; i<plink_att_num; i++){ if(i) { // Retrying on a network error LOGJOBMSG( fmt("PLINK connection failed: %s\nRetrying %d more times", (const gmdChar*)errmsg, plink_att_num - i) ); gmdMilliSleep(plink_retry_delay); // delay before a retry } gmdArrayString out, err; //ttimer.Resume(); res = gmdExecute(pscp_pre + args, out, err); //ttimer.Pause(); if(res == -1) return( set_err(EXECUTE_ERROR, "Error executing PSCP!") ); if(dump_commands && res != 0) LOGJOBMSG4( (pCSTR) ("------ pscp_execute (error)------\n" " cout=" + ArrayToString(out)+"\n" " cerr=" + ArrayToString(err)+"\n" )); if(res == 0) break; errmsg = ArrayToString(err); if( !errmsg.StartsWith("Fatal: Network error:") ) break; } if(res) { // Replace 'res' by an internal error code if(i >= plink_att_num) res = CONNECTION_ERROR; else if( ( errmsg.Contains("no such file or directory") || errmsg.Contains("matched no files") ) && !errmsg.Contains("unable to open") ) res = NO_INPUT_FILE; else res = COPY_ERROR; set_err(res, errmsg); } return res; }
int gmShellPlink::execute(const gmdString& cmd, gmdArrayString& out, gmdArrayString& err){ // Execute Shell command int i, res; gmdString errmsg; execute_begin(cmd, out, err); if(!auth_defined) return execute_error( set_err(CONNECTION_ERROR, "PLINK: Authentification method is not defined, " "check 'login', 'host' and 'plink_args' parameters!" ) ); // Screed double quotes gmdString cmd_scr(cmd); cmd_scr.Replace("\"", "\\\""); // Avoid empty command that switches plink into the interactive mode if( cmd_scr.IsEmpty() ) cmd_scr = "#"; for(i=0; i<plink_att_num; i++){ if(i) { // Retrying on a network error LOGJOBMSG( fmt("PLINK connection failed: %s\nRetrying %d more times", (const gmdChar*)errmsg, plink_att_num - i) ); gmdMilliSleep(plink_retry_delay); // delay before a retry } if(dump_commands) LOGJOBMSG4( (pCSTR)("------ execute (plink)------\n" + plink_pre + cmd_scr + '\"') ); res = gmdExecute(plink_pre + cmd_scr + '\"', out, err); if(res == -1) { execute_end(res, out, err); return execute_error( set_err(EXECUTE_ERROR, "Error executing PLINK") ); } else if(res == 0) break; errmsg = ArrayToString(err); if( !errmsg.StartsWith("Unable to open connection") ) break; } if(i >= plink_att_num){ execute_end(-1, out, err); // pausing timer return set_err(CONNECTION_ERROR, errmsg); } return execute_end(res, out, err); }