setting environment variables on the remote host

Ryan Braud rbraud at cs.ucsd.edu
Tue Oct 2 19:02:59 MEST 2007


Hi,

I am working with the MindTerm source code to establish a remote shell 
on a machine in a program I am writing.  Currently, I am using the 
SSH2SimpleClient object, and I can connect just fine.  However, I wanted 
to set some environment variables in this shell connection.  Below is a 
sketch of my code, which is currently not working:

<code>
Socket sock = new Socket();
System.out.println("Trying to connect to " + theIP);
sock.connect(new InetSocketAddress(theIP, 22), 5000);
transport = new SSH2Transport(sock, prefs, secureRandom);
client = new SSH2SimpleClient(transport, user, keyFile, "");
console = new SSH2ConsoleRemote(client.getConnection());

SSH2TerminalAdapterImpl termAdapter = new SSH2TerminalAdapterImpl(terminal);

if (!console.terminal(termAdapter)) {
     throw new Exception("Couldn't start terminal!");
}

SSH2SessionChannel sess = client.getConnection().newSession();
System.out.println(sess.setEnvironment("ENV1", "blah");
System.out.println(sess.setEnvironment("ENV2", "blah2");

// Wait for user to close remote shell
exitStatus = console.waitForExitStatus();
</code>

When I try to set the environment variables with setEnvironment, it always 
returns false.  Other than that, the connection is established fine and I 
end up with my remote shell.  I'm not positive if this is the right way to 
set environment variables, since I did not find any documentation on this 
method or about setting environment variables in general.

Does anyone know if I am going about this the right way, or why this might 
not be working?

Thanks,
Ryan


More information about the Mindterm-users mailing list