• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3  * Please refer to the LICENSE.txt for licensing details.
4  */
5 package ch.ethz.ssh2.packets;
6 
7 import java.io.IOException;
8 import java.io.UnsupportedEncodingException;
9 
10 /**
11  * PacketSessionExecCommand.
12  *
13  * @author Christian Plattner
14  * @version $Id: PacketSessionExecCommand.java 5 2011-05-27 12:59:54Z dkocher@sudo.ch $
15  */
16 public class PacketSessionExecCommand
17 {
18 	byte[] payload;
19 
20 	public int recipientChannelID;
21 	public boolean wantReply;
22 	public String command;
23 
PacketSessionExecCommand(int recipientChannelID, boolean wantReply, String command)24 	public PacketSessionExecCommand(int recipientChannelID, boolean wantReply, String command)
25 	{
26 		this.recipientChannelID = recipientChannelID;
27 		this.wantReply = wantReply;
28 		this.command = command;
29 	}
30 
getPayload()31 	public byte[] getPayload() throws IOException
32 	{
33 		return this.getPayload(null);
34 	}
35 
getPayload(String charsetName)36 	public byte[] getPayload(String charsetName) throws UnsupportedEncodingException
37 	{
38 		if (payload == null)
39 		{
40 			TypesWriter tw = new TypesWriter();
41 			tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST);
42 			tw.writeUINT32(recipientChannelID);
43 			tw.writeString("exec");
44 			tw.writeBoolean(wantReply);
45 			tw.writeString(command, charsetName);
46 			payload = tw.getBytes();
47 		}
48 		return payload;
49 	}
50 }
51