{
privateKey = ScpHelper.getPrivateKey( authenticationInfo );
}
catch ( FileNotFoundException e )
{
throw new CommandExecutionException( e.getMessage(), e );
}
Commandline cl = createBaseCommandLine( putty, sshExecutable, privateKey );
int port =
repository.getPort() == WagonConstants.UNKNOWN_PORT ? ScpHelper.DEFAULT_SSH_PORT : repository.getPort();
if ( port != ScpHelper.DEFAULT_SSH_PORT )
{
if ( putty )
{
cl.createArg().setLine( "-P " + port );
}
else
{
cl.createArg().setLine( "-p " + port );
}
}
if ( sshArgs != null )
{
cl.createArg().setLine( sshArgs );
}
String remoteHost = this.buildRemoteHost();
cl.createArg().setValue( remoteHost );
cl.createArg().setValue( command );
fireSessionDebug( "Executing command: " + cl.toString() );
try
{
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine( cl, out, err );
Streams streams = new Streams();
streams.setOut( out.getOutput() );
streams.setErr( err.getOutput() );
fireSessionDebug( streams.getOut() );
fireSessionDebug( streams.getErr() );
if ( exitCode != 0 )
{
if ( !ignoreFailures || exitCode == SSH_FATAL_EXIT_CODE )
{
throw new CommandExecutionException( "Exit code " + exitCode + " - " + err.getOutput() );
}
}
return streams;
}
catch ( CommandLineException e )
{
throw new CommandExecutionException( "Error executing command line", e );
}
}