use of com.jcraft.jsch.Channel in project ant by apache.
the class ScpToMessage method doSingleTransfer.
private void doSingleTransfer() throws IOException, JSchException {
StringBuilder sb = new StringBuilder("scp -t ");
if (getPreserveLastModified()) {
sb.append("-p ");
}
if (getCompressed()) {
sb.append("-C ");
}
sb.append(remotePath);
final String cmd = sb.toString();
final Channel channel = openExecChannel(cmd);
try {
final OutputStream out = channel.getOutputStream();
final InputStream in = channel.getInputStream();
channel.connect();
waitForAck(in);
sendFileToRemote(localFile, in, out);
} finally {
if (channel != null) {
channel.disconnect();
}
}
}
use of com.jcraft.jsch.Channel in project ant by apache.
the class ScpToMessage method doMultipleTransfer.
private void doMultipleTransfer() throws IOException, JSchException {
StringBuilder sb = new StringBuilder("scp -r -d -t ");
if (getPreserveLastModified()) {
sb.append("-p ");
}
if (getCompressed()) {
sb.append("-C ");
}
sb.append(remotePath);
final Channel channel = openExecChannel(sb.toString());
try {
final OutputStream out = channel.getOutputStream();
final InputStream in = channel.getInputStream();
channel.connect();
waitForAck(in);
for (Directory current : directoryList) {
sendDirectory(current, in, out);
}
} finally {
if (channel != null) {
channel.disconnect();
}
}
}
use of com.jcraft.jsch.Channel in project ASAP by salmant.
the class SS1 method How_many_existing_servers.
// ///////////////////////////////////////////
public static int How_many_existing_servers() {
int i = 0;
String haproy_ip = "194.249.1.110";
String haproy_host_user = "root";
String haproy_host_password = "*****************";
try {
String command = "cat /etc/haproxy/haproxy.cfg";
JSch jsch = new JSch();
com.jcraft.jsch.Session session = jsch.getSession(haproy_host_user, haproy_ip, 22);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
;
session.setPassword(haproy_host_password);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream input = channel.getInputStream();
channel.connect();
try {
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(inputReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("-www"))
i++;
// System.out.println(line);
}
bufferedReader.close();
inputReader.close();
} catch (IOException ex) {
ex.printStackTrace();
return i;
}
channel.disconnect();
session.disconnect();
return i;
} catch (Exception ex) {
ex.printStackTrace();
return i;
}
}
use of com.jcraft.jsch.Channel in project ASAP by salmant.
the class THRES1 method How_many_existing_servers.
// ///////////////////////////////////////////
public static int How_many_existing_servers() {
int i = 0;
String haproy_ip = "194.249.1.110";
String haproy_host_user = "root";
String haproy_host_password = "****************";
try {
String command = "cat /etc/haproxy/haproxy.cfg";
JSch jsch = new JSch();
com.jcraft.jsch.Session session = jsch.getSession(haproy_host_user, haproy_ip, 22);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
;
session.setPassword(haproy_host_password);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream input = channel.getInputStream();
channel.connect();
try {
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(inputReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("-www"))
i++;
// System.out.println(line);
}
bufferedReader.close();
inputReader.close();
} catch (IOException ex) {
ex.printStackTrace();
return i;
}
channel.disconnect();
session.disconnect();
return i;
} catch (Exception ex) {
ex.printStackTrace();
return i;
}
}
use of com.jcraft.jsch.Channel in project ASAP by salmant.
the class THRES2 method How_many_existing_servers.
// ///////////////////////////////////////////
public static int How_many_existing_servers() {
int i = 0;
String haproy_ip = "194.249.1.110";
String haproy_host_user = "root";
String haproy_host_password = "****************";
try {
String command = "cat /etc/haproxy/haproxy.cfg";
JSch jsch = new JSch();
com.jcraft.jsch.Session session = jsch.getSession(haproy_host_user, haproy_ip, 22);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
;
session.setPassword(haproy_host_password);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream input = channel.getInputStream();
channel.connect();
try {
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(inputReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("-www"))
i++;
// System.out.println(line);
}
bufferedReader.close();
inputReader.close();
} catch (IOException ex) {
ex.printStackTrace();
return i;
}
channel.disconnect();
session.disconnect();
return i;
} catch (Exception ex) {
ex.printStackTrace();
return i;
}
}
Aggregations