Search in sources :

Example 21 with Channel

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) OutputStream(java.io.OutputStream)

Example 22 with Channel

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) OutputStream(java.io.OutputStream)

Example 23 with Channel

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) IOException(java.io.IOException) JSch(com.jcraft.jsch.JSch) Properties(java.util.Properties) ChannelExec(com.jcraft.jsch.ChannelExec) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Example 24 with Channel

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) IOException(java.io.IOException) JSch(com.jcraft.jsch.JSch) Properties(java.util.Properties) ChannelExec(com.jcraft.jsch.ChannelExec) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Example 25 with Channel

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) IOException(java.io.IOException) JSch(com.jcraft.jsch.JSch) Properties(java.util.Properties) ChannelExec(com.jcraft.jsch.ChannelExec) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Aggregations

Channel (com.jcraft.jsch.Channel)63 InputStream (java.io.InputStream)38 ChannelExec (com.jcraft.jsch.ChannelExec)33 IOException (java.io.IOException)33 JSch (com.jcraft.jsch.JSch)32 JSchException (com.jcraft.jsch.JSchException)30 Session (com.jcraft.jsch.Session)27 FileInputStream (java.io.FileInputStream)19 ChannelSftp (com.jcraft.jsch.ChannelSftp)18 OutputStream (java.io.OutputStream)17 BufferedReader (java.io.BufferedReader)15 File (java.io.File)13 InputStreamReader (java.io.InputStreamReader)13 Properties (java.util.Properties)13 SftpException (com.jcraft.jsch.SftpException)12 FileOutputStream (java.io.FileOutputStream)10 UserInfo (com.jcraft.jsch.UserInfo)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 GFacException (org.apache.airavata.gfac.core.GFacException)4 SSHApiException (org.apache.airavata.gfac.core.SSHApiException)3