Package com.jcraft.jsch

Examples of com.jcraft.jsch.Session.connect()


  }

  public Session connect(String host) throws JSchException {
    Session session = jsch.getSession(login, host);
    session.setUserInfo(userInfo);
    session.connect();
   
    return session;
  }
}
View Full Code Here


      JSch jsch = new JSch();
      jsch.addIdentity(keyFile.getAbsolutePath());
      Session session = jsch.getSession("root", targetHostName, 22);
      UserInfo ui = new SshUser();
      session.setUserInfo(ui);
      session.connect();

      String command = "scp -p -t  " + targetFileName;
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
View Full Code Here

      JSch jsch = new JSch();
      jsch.addIdentity(file.getAbsolutePath());
      Session session = jsch.getSession("root", dnsName, 22);
      UserInfo ui = new SshUser();
      session.setUserInfo(ui);
      session.connect();

      Channel channel = session.openChannel("exec");

      ((ChannelExec) channel).setCommand(command);
      ((ChannelExec) channel).setErrStream(System.out);
View Full Code Here

                    session = jsch.getSession(username,host);
                if(pemFile != null) {
                    jsch.addIdentity(pemFile.getAbsolutePath(), pemPassword);
                }
                session.setUserInfo(new cfUserInfo(host,username,userPassword,pemFile,pemPassword,passFile));
                session.connect();
                Message.verbose(":: SSH :: connected to "+host+"!");
                setSession(username, host, port, session);
            } catch (JSchException e) {
                if (passFile.exists()) {
                    passFile.delete();
View Full Code Here

            }

            public void showMessage(String message) {
            }
        });
        session.connect();
        return session;
    }

    protected ClientSession createNativeSession() throws Exception {
        SshClient client = SshClient.setUpDefaultClient();
View Full Code Here

    UserInfoImpl ui = new UserInfoImpl(this.prop);
                    
    jsch.addIdentity("C:\\cygwin\\home\\Stelk\\.ssh\\id_rsa");
    Session session =  jsch.getSession("root", "192.168.1.1", 22);
    session.setUserInfo(ui);
    session.connect();
    String command = "iptables -L INPUT -nv --line-numbers";
    try {
        Channel channel=session.openChannel("exec");
        ((ChannelExec)channel).setCommand(command);
        channel.setInputStream(null);
View Full Code Here

                @Override
                public void showMessage(String message) {
                }
            });
            // in the process of connecting, "[localhost]:<port>" is added to the knownHostsFile
            s.connect();
            s.disconnect();
        } catch (JSchException e) {
            LOG.info("Could not add [localhost] to known hosts", e);
        }
    }
View Full Code Here

    FileInputStream fis = null;
    OutputStream out = null;
    InputStream in = null;
    try {
      Session session = pContext.createSession();
      session.connect();

      Channel channel = sendCommand(pRemoteFile, session);

     
       out = channel.getOutputStream();
View Full Code Here

public class Exec {
  public static String exec(SecureContext pContext, String pCommand)
      throws JSchException, IOException {
    Session session = pContext.createSession();
    session.connect();
    String result = "";
    Channel channel = session.openChannel("exec");
    ((ChannelExec) channel).setCommand(pCommand);
    final ByteArrayOutputStream myOut = new ByteArrayOutputStream();
    ((ChannelExec) channel).setErrStream(new PrintStream(myOut));
View Full Code Here

                            remote.getPort());

                    // TODO: Strict host key checking
                    session.setConfig("StrictHostKeyChecking", "no");
                    // session.setPassword("super_secre_password");
                    session.connect();
                } catch (JSchException e) {
                    session = null;
                    throw new IOException("Error connecting to SSH (" + getInfo() + ")", e);
                }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.